Ejemplo n.º 1
0
    def test07b_closepolygons(self):
        "Testing closing Polygon objects."
        # Both rings in this geometry are not closed.
        poly = OGRGeometry(
            'POLYGON((0 0, 5 0, 5 5, 0 5), (1 1, 2 1, 2 2, 2 1))')
        self.assertEqual(8, poly.point_count)
        print "\nBEGIN - expecting IllegalArgumentException; safe to ignore.\n"
        try:
            c = poly.centroid
        except OGRException:
            # Should raise an OGR exception, rings are not closed
            pass
        else:
            self.fail('Should have raised an OGRException!')
        print "\nEND - expecting IllegalArgumentException; safe to ignore.\n"

        # Closing the rings -- doesn't work on GDAL versions 1.4.1 and below:
        # http://trac.osgeo.org/gdal/ticket/1673
        major, minor1, minor2 = gdal_version().split('.')
        if major == '1':
            iminor1 = int(minor1)
            if iminor1 < 4 or (iminor1 == 4 and minor2.startswith('1')): return
        poly.close_rings()
        self.assertEqual(
            10, poly.point_count)  # Two closing points should've been added
        self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid)
Ejemplo n.º 2
0
    def test07b_closepolygons(self):
        "Testing closing Polygon objects."
        # Both rings in this geometry are not closed.
        poly = OGRGeometry("POLYGON((0 0, 5 0, 5 5, 0 5), (1 1, 2 1, 2 2, 2 1))")
        self.assertEqual(8, poly.point_count)
        print "\nBEGIN - expecting IllegalArgumentException; safe to ignore.\n"
        try:
            c = poly.centroid
        except OGRException:
            # Should raise an OGR exception, rings are not closed
            pass
        else:
            self.fail("Should have raised an OGRException!")
        print "\nEND - expecting IllegalArgumentException; safe to ignore.\n"

        # Closing the rings -- doesn't work on GDAL versions 1.4.1 and below:
        # http://trac.osgeo.org/gdal/ticket/1673
        major, minor1, minor2 = gdal_version().split(".")
        if major == "1":
            iminor1 = int(minor1)
            if iminor1 < 4 or (iminor1 == 4 and minor2.startswith("1")):
                return
        poly.close_rings()
        self.assertEqual(10, poly.point_count)  # Two closing points should've been added
        self.assertEqual(OGRGeometry("POINT(2.5 2.5)"), poly.centroid)
Ejemplo n.º 3
0
def pytest_configure():
    try:
        gdal_ver = gdal_full_version().decode()
    except ctypes.ArgumentError:
        # gdal_full_version() is broken in Django<3.1,
        # see https://code.djangoproject.com/ticket/31292
        gdal_ver = gdal_version().decode()

    geos_ver = geos_version().decode()
    print(
        f'Running with Django {django.__version__}, GDAL="{gdal_ver}" GEOS="{geos_ver}"'
    )
    print(
        f"Using GISSERVER_USE_DB_RENDERING={conf.GISSERVER_USE_DB_RENDERING}")

    for url in (
            "http://schemas.opengis.net/wfs/2.0/wfs.xsd",
            "http://schemas.opengis.net/gml/3.2.1/gml.xsd",
    ):
        if not XSD_ROOT.joinpath(url.replace("http://", "")).exists():
            print(f"Caching {url} to {XSD_ROOT.absolute()}")
            download_schema(url)
def fix_extent(apps, schema_editor):
    try:
        Project = apps.get_model("gvsigol_core", "Project")
        from django.contrib.gis import gdal
        major_version = gdal.gdal_version().split(".")[0]
        if int(major_version) >= 3:
            # fix effect of previous migration on GDAL 3 installations
            try:
                # newer Django versions include AxisOrder settings to manage this issue
                from django.contrib.gis.gdal import AxisOrder  # @UnresolvedImport is expected in Diago < 3.1
                # newer Django versions include AxisOrder settings to manage this issue
                # if AxisOrder class exists, the transformation on 0029_fill_project_extent4326
                # should be successful, because AxisOrder.TRADITIONAL is the default behaviour
                return
            except:
                pass
            from django.contrib.gis.gdal import SpatialReference, CoordTransform
            from django.contrib.gis.geos import Point
            crs4326 = SpatialReference("EPSG:4326")
            crs3857 = SpatialReference("EPSG:3857")
            transform = CoordTransform(crs3857, crs4326)
            for project in Project.objects.all():
                extent3857_minx, extent3857_miny, extent3857_maxx, extent3857_maxy = [
                    float(f) for f in project.extent.split(',')
                ]
                point = Point(extent3857_minx, extent3857_miny, srid=3857)
                point.transform(transform)
                project.extent4326_miny, project.extent4326_minx = point.coords

                point = Point(extent3857_maxx, extent3857_maxy, srid=3857)
                point.transform(transform)
                project.extent4326_maxy, project.extent4326_maxx = point.coords
                project.save()

    except Exception as error:
        import logging
        logger = logging.getLogger()
        logger.exception("error")
        print str(error)
Ejemplo n.º 5
0
 def test_gdal_version(self):
     if GDAL_VERSION:
         self.assertEqual(gdal_version(), ("%s.%s.%s" % GDAL_VERSION).encode())
     else:
         self.assertIn(b".", gdal_version())
Ejemplo n.º 6
0
 def test_gdal_full_version(self):
     full_version = gdal_full_version()
     self.assertIn(gdal_version(), full_version)
     self.assertTrue(full_version.startswith(b"GDAL"))
Ejemplo n.º 7
0
 def test_gdal_version(self):
     if GDAL_VERSION:
         self.assertEqual(gdal_version(),
                          ('%s.%s.%s' % GDAL_VERSION).encode())
     else:
         self.assertIn(b'.', gdal_version())