How to use the neomodel.contrib.spatial_properties.PointProperty function in neomodel

To help you get started, we’ve selected a few neomodel 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
def test_spatial_point_property():
    """
    Tests that specific modes of instantiation fail as expected.

    :return:
    """

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    with pytest.raises(ValueError, match='Invalid CRS\(None\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty()

    with pytest.raises(ValueError, match='Invalid CRS\(crs_isaak\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(crs='crs_isaak')

    with pytest.raises(TypeError, match='Invalid default value'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(default=(0.0, 0.0), crs='cartesian')
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
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
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
def test_spatial_point_property():
    """
    Tests that specific modes of instantiation fail as expected.

    :return:
    """

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    with pytest.raises(ValueError, match='Invalid CRS\(None\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty()

    with pytest.raises(ValueError, match='Invalid CRS\(crs_isaak\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(crs='crs_isaak')

    with pytest.raises(TypeError, match='Invalid default value'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(default=(0.0, 0.0), crs='cartesian')
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
Tests that specific modes of instantiation fail as expected.

    :return:
    """

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    with pytest.raises(ValueError, match='Invalid CRS\(None\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty()

    with pytest.raises(ValueError, match='Invalid CRS\(crs_isaak\)'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(crs='crs_isaak')

    with pytest.raises(TypeError, match='Invalid default value'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(default=(0.0, 0.0), crs='cartesian')
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_spatial_point_property():
    """
    Tests that specific modes of instantiation fail as expected.

    :return:
    """

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    with pytest.raises(ValueError, message='Expected ValueError("Invalid CRS (CRS not specified)")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty()

    with pytest.raises(ValueError, message='Expected ValueError("Invalid CRS (CRS not acceptable)")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(crs='crs_isaak')

    with pytest.raises(TypeError, message='Expected TypeError("Invalid default value")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(default=(0.0, 0.0), crs='cartesian')
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_default_value():
    """
    Tests that the default value passing mechanism works as expected with NeomodelPoint values.
    :return:
    """

    def get_some_point():
        return neomodel.contrib.spatial_properties.NeomodelPoint((random.random(),random.random()))

    class LocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity to try out the default value assignment.
        """
        identifier = neomodel.UniqueIdProperty()
        location = neomodel.contrib.spatial_properties.PointProperty(crs='cartesian', default=get_some_point)

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
    
    # Save an object
    an_object = LocalisableEntity().save()
    coords = an_object.location.coords[0]
    # Retrieve it
    retrieved_object = LocalisableEntity.nodes.get(identifier=an_object.identifier)
    # Check against an independently created value
    assert retrieved_object.location == neomodel.contrib.spatial_properties.NeomodelPoint(coords), \
        "Default value assignment failed."
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
Tests that specific modes of instantiation fail as expected.

    :return:
    """

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    with pytest.raises(ValueError, message='Expected ValueError("Invalid CRS (CRS not specified)")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty()

    with pytest.raises(ValueError, message='Expected ValueError("Invalid CRS (CRS not acceptable)")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(crs='crs_isaak')

    with pytest.raises(TypeError, message='Expected TypeError("Invalid default value")'):
        a_point_property = neomodel.contrib.spatial_properties.PointProperty(default=(0.0, 0.0), crs='cartesian')
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_default_value():
    """
    Tests that the default value passing mechanism works as expected with NeomodelPoint values.
    :return:
    """

    def get_some_point():
        return neomodel.contrib.spatial_properties.NeomodelPoint((random.random(),random.random()))

    class LocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity to try out the default value assignment.
        """
        identifier = neomodel.UniqueIdProperty()
        location = neomodel.contrib.spatial_properties.PointProperty(crs='cartesian', default=get_some_point)

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    # Save an object
    an_object = LocalisableEntity().save()
    coords = an_object.location.coords[0]
    # Retrieve it
    retrieved_object = LocalisableEntity.nodes.get(identifier=an_object.identifier)
    # Check against an independently created value
    assert retrieved_object.location == neomodel.contrib.spatial_properties.NeomodelPoint(coords), \
        "Default value assignment failed."