How to use the neo4j.v1.spatial.Point function in neo4j

To help you get started, we’ve selected a few neo4j examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    CRS_TO_SRID = dict([(value, key) for key, value in neomodel.contrib.spatial_properties.SRID_TO_CRS.items()])
    # Values to construct and expect during deflation
    values_from_neomodel = [(neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0), crs='cartesian'),
                             'Expected Neo4J 2d cartesian point when deflating Neomodel 2d cartesian point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0, 0.0), crs='cartesian-3d'),
                             'Expected Neo4J 3d cartesian point when deflating Neomodel 3d cartesian point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0), crs='wgs-84'),
                             'Expected Neo4J 2d geographical point when deflating Neomodel 2d geographical point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0, 0.0), crs='wgs-84-3d'),
                             'Expected Neo4J 3d geographical point when deflating Neomodel 3d geographical point')]

    # Run the above tests.
    for a_value in values_from_neomodel:
        expected_point = neo4j.v1.spatial.Point(tuple(a_value[0].coords[0]))
        expected_point.srid = CRS_TO_SRID[a_value[0].crs]
        deflated_point = neomodel.contrib.spatial_properties.PointProperty(crs=a_value[0].crs).deflate(a_value[0])
        basic_type_assertions(expected_point, deflated_point, '{}, received {}'.format(a_value[1], deflated_point),
                              check_neo4j_points=True)
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    CRS_TO_SRID = dict([(value, key) for key, value in neomodel.contrib.spatial_properties.SRID_TO_CRS.items()])
    # Values to construct and expect during deflation
    values_from_neomodel = [(neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0), crs='cartesian'),
                             'Expected Neo4J 2d cartesian point when deflating Neomodel 2d cartesian point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0, 0.0), crs='cartesian-3d'),
                             'Expected Neo4J 3d cartesian point when deflating Neomodel 3d cartesian point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0), crs='wgs-84'),
                             'Expected Neo4J 2d geographical point when deflating Neomodel 2d geographical point'),
                            (neomodel.contrib.spatial_properties.NeomodelPoint((0.0, 0.0, 0.0), crs='wgs-84-3d'),
                             'Expected Neo4J 3d geographical point when deflating Neomodel 3d geographical point')]

    # Run the above tests.
    for a_value in values_from_neomodel:
        expected_point = neo4j.v1.spatial.Point(tuple(a_value[0].coords[0]))
        expected_point.srid = CRS_TO_SRID[a_value[0].crs]
        deflated_point = neomodel.contrib.spatial_properties.PointProperty(crs=a_value[0].crs).deflate(a_value[0])
        basic_type_assertions(expected_point, deflated_point, '{}, received {}'.format(a_value[1], deflated_point),
                              check_neo4j_points=True)
github neo4j-contrib / neomodel / neomodel / contrib / spatial_properties.py View on Github external
def inflate(self, value):
        """
        Handles the marshalling from Neo4J POINT to NeomodelPoint

        :param value: Value returned from the database
        :type value: Neo4J POINT
        :return: NeomodelPoint
        """
        if not isinstance(value,neo4j.v1.spatial.Point):
            raise TypeError('Invalid datatype to inflate. Expected POINT datatype, received {}'.format(type(value)))

        try:
            value_point_crs = SRID_TO_CRS[value.srid]
        except KeyError:
            raise ValueError('Invalid SRID to inflate. '
                             'Expected one of {}, received {}'.format(SRID_TO_CRS.keys(), value.srid))

        if self._crs != value_point_crs:
            raise ValueError('Invalid CRS. '
                             'Expected POINT defined over {}, received {}'.format(self._crs, value_point_crs))
        # cartesian
        if value.srid == 7203:
            return NeomodelPoint(x=value.x, y=value.y)
        # cartesian-3d
        elif value.srid == 9157: