示例#1
0
    def test_custom_srid(self):
        """ Test with a srid unknown from GDAL """
        pnt = Point(111200, 220900, srid=999999)
        self.assertTrue(pnt.ewkt.startswith("SRID=999999;POINT (111200.0"))
        self.assertIsInstance(pnt.ogr, gdal.OGRGeometry)
        self.assertIsNone(pnt.srs)

        # Test conversion from custom to a known srid
        c2w = gdal.CoordTransform(
            gdal.SpatialReference(
                '+proj=mill +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +R_A +ellps=WGS84 '
                '+datum=WGS84 +units=m +no_defs'), gdal.SpatialReference(4326))
        new_pnt = pnt.transform(c2w, clone=True)
        self.assertEqual(new_pnt.srid, 4326)
        self.assertAlmostEqual(new_pnt.x, 1, 3)
        self.assertAlmostEqual(new_pnt.y, 2, 3)
示例#2
0
文件: srs.py 项目: shikhach/quac
def transform(geom, srid, always_copy=False):
    '''Return geom transformed to SRID srid. The returned object may be geom
      itself, if no transformation is needed, unless always_copy==True, in
      which case a copy is always made.'''
    # NOTE: This function works around a Django bug that prevents transforming
    # from a custom SRID (https://code.djangoproject.com/ticket/19171). The
    # workaround is to set a fake SRID on the source object, do the
    # transformation, and the put the real SRID back.
    if (geom.srid == srid and not always_copy):
        return geom
    try:
        ct = TRANSFORMERS[(geom.srid, srid)]
    except KeyError:
        ct = gdal.CoordTransform(SRS[geom.srid], SRS[srid])
        TRANSFORMERS[(geom.srid, srid)] = ct
    source_srid_real = geom.srid
    geom.srid = SRID_WGS84
    result = geom.transform(ct, clone=True)
    geom.srid = source_srid_real
    return result
示例#3
0
    def test_transform(self):
        "Testing `transform` method."
        orig = GEOSGeometry('POINT (-104.609 38.255)', 4326)
        trans = GEOSGeometry('POINT (992385.4472045 481455.4944650)', 2774)

        # Using a srid, a SpatialReference object, and a CoordTransform object
        # for transformations.
        t1, t2, t3 = orig.clone(), orig.clone(), orig.clone()
        t1.transform(trans.srid)
        t2.transform(gdal.SpatialReference('EPSG:2774'))
        ct = gdal.CoordTransform(gdal.SpatialReference('WGS84'), gdal.SpatialReference(2774))
        t3.transform(ct)

        # Testing use of the `clone` keyword.
        k1 = orig.clone()
        k2 = k1.transform(trans.srid, clone=True)
        self.assertEqual(k1, orig)
        self.assertNotEqual(k1, k2)

        prec = 3
        for p in (t1, t2, t3, k2):
            self.assertAlmostEqual(trans.x, p.x, prec)
            self.assertAlmostEqual(trans.y, p.y, prec)