Beispiel #1
0
    def deflate(self, value):
        """
        Handles the marshalling from NeomodelPoint to Neo4J POINT

        :param value: The point that was assigned as value to a property in the model
        :type value: NeomodelPoint
        :return: Neo4J POINT
        """
        if not isinstance(value, NeomodelPoint):
            raise TypeError(
                'Invalid datatype to deflate. Expected NeomodelPoint, received {}'
                .format(type(value)))

        if not value.crs == self._crs:
            raise ValueError('Invalid CRS. '
                             'Expected NeomodelPoint defined over {}, '
                             'received NeomodelPoint defined over {}'.format(
                                 self._crs, value.crs))

        if value.crs == 'cartesian-3d':
            return CartesianPoint((value.x, value.y, value.z))
        elif value.crs == 'cartesian':
            return CartesianPoint((value.x, value.y))
        elif value.crs == 'wgs-84':
            return WGS84Point((value.longitude, value.latitude))
        elif value.crs == 'wgs-84-3d':
            return WGS84Point((value.longitude, value.latitude, value.height))
Beispiel #2
0
 def test_point_array(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         data = [WGS84Point((1.23, 4.56)), WGS84Point((9.87, 6.54))]
         value = session.write_transaction(run_and_rollback,
                                           "CREATE (a {x:$x}) RETURN a.x",
                                           x=data)
         self.assertEqual(value, data)
Beispiel #3
0
    def create_location_node(self, tx, location_id, attrs):
        """Insert one location node.

        Parameters
        ----------
        tx : :class:`neo4j.Database.session.transaction`
            A neo4j transaction.
        location_id : str
            Location id.
        attrs : :class:`pandas.DataFrame`
            Attributes associated with this location.

        """

        attrs = attrs.where(attrs.notnull(), None).to_dict()
        attrs['location_id'] = location_id
        attrs['gps'] = WGS84Point(
            (float(attrs['longitude']), float(attrs['latitude'])))
        del attrs['longitude']
        del attrs['latitude']
        statement = ('CREATE (a:location {location_id: $location_id, '
                     'city: $city, state: $state, country: $country, '
                     'gps: $gps, county: $county, state_fips: $state_fips, '
                     'county_fips: $county_fips})')
        tx.run(statement, **attrs)
Beispiel #4
0
 def test_wgs84_point(self):
     self.assert_supports_spatial_types()
     with self.driver.session() as session:
         result = session.run("CYPHER runtime=interpreted WITH $point AS point "
                              "RETURN point.latitude, point.longitude",
                              point=WGS84Point((1.23, 4.56)))
         latitude, longitude = result.single()
         self.assertEqual(longitude, 1.23)
         self.assertEqual(latitude, 4.56)