Example #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))
Example #2
0
 def test_cartesian_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.x, point.y",
                              point=CartesianPoint((1.23, 4.56)))
         x, y = result.single()
         self.assertEqual(x, 1.23)
         self.assertEqual(y, 4.56)
Example #3
0
    def _insert_patches(tx, patches):

        items = [{
            "des":
            json.dumps(p['des'].tolist(), separators=(',', ':')),
            "scene":
            p['scene'],
            "size":
            p['size'],
            "loc":
            CartesianPoint((float(p['loc'][0]), float(p['loc'][1])))
        } for p in patches]
        query = "UNWIND {props} AS properties CREATE (patch:Patch) SET patch = properties RETURN patch"
        record_to_object_func = PatchGraphDatabase._patch_from_node
        unwind_name = 'props'
        return_name = 'patch'

        return PatchGraphDatabase._batch_query(tx, items, query,
                                               record_to_object_func,
                                               unwind_name, return_name)