当前位置: 首页>>代码示例>>Python>>正文


Python gdal.CoordTransform方法代码示例

本文整理汇总了Python中django.contrib.gis.gdal.CoordTransform方法的典型用法代码示例。如果您正苦于以下问题:Python gdal.CoordTransform方法的具体用法?Python gdal.CoordTransform怎么用?Python gdal.CoordTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.gis.gdal的用法示例。


在下文中一共展示了gdal.CoordTransform方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_dump_object

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def get_dump_object(self, obj):
        data = {
            "type": "Feature",
            "properties": self._current,
        }
        if self._geometry:
            if self._geometry.srid != self.srid:
                # If needed, transform the geometry in the srid of the global geojson srid
                if not HAS_GDAL:
                    raise SerializationError(
                        'Unable to convert geometry to SRID %s when GDAL is not installed.' % self.srid
                    )
                if self._geometry.srid not in self._cts:
                    srs = SpatialReference(self.srid)
                    self._cts[self._geometry.srid] = CoordTransform(self._geometry.srs, srs)
                self._geometry.transform(self._cts[self._geometry.srid])
            data["geometry"] = eval(self._geometry.geojson)
        else:
            data["geometry"] = None
        return data 
开发者ID:drexly,项目名称:openhgsenti,代码行数:22,代码来源:geojson.py

示例2: test_custom_srid

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def test_custom_srid(self):
        """Test with a null srid and a srid unknown to GDAL."""
        for srid in [None, 999999]:
            pnt = Point(111200, 220900, srid=srid)
            self.assertTrue(pnt.ewkt.startswith(("SRID=%s;" % srid if srid else '') + "POINT (111200"))
            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) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_geos.py

示例3: test_transform

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
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) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:test_geos.py

示例4: start_serialization

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def start_serialization(self):
        if not HAS_GDAL:
            # GDAL is needed for the geometry.geojson call
            raise SerializationError("The geojson serializer requires the GDAL library.")
        self._init_options()
        self._cts = {}  # cache of CoordTransform's
        self.stream.write(
            '{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:%d"}},'
            ' "features": [' % self.srs.srid) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:geojson.py

示例5: get_dump_object

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def get_dump_object(self, obj):
        data = {
            "type": "Feature",
            "properties": self._current,
        }
        if self._geometry:
            if self._geometry.srid != self.srs.srid:
                # If needed, transform the geometry in the srid of the global geojson srid
                if self._geometry.srid not in self._cts:
                    self._cts[self._geometry.srid] = CoordTransform(self._geometry.srs, self.srs)
                self._geometry.transform(self._cts[self._geometry.srid])
            data["geometry"] = eval(self._geometry.geojson)
        else:
            data["geometry"] = None
        return data 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:geojson.py

示例6: test_get_event_list_verify_bbox_filter

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def test_get_event_list_verify_bbox_filter(api_client, event, event2):
    # API parameters must be provided in EPSG:4326 instead of the database SRS
    left_bottom = Point(25, 25)
    right_top = Point(75, 75)
    ct = CoordTransform(SpatialReference(settings.PROJECTION_SRID), SpatialReference(4326))
    left_bottom.transform(ct)
    right_top.transform(ct)
    bbox_string = f"{left_bottom.x},{left_bottom.y},{right_top.x},{right_top.y}"
    response = get_list(api_client, data={'bbox': bbox_string})
    # this way we will catch any errors if the default SRS changes, breaking the API
    assert event.id in [entry['id'] for entry in response.data['data']]
    assert event2.id not in [entry['id'] for entry in response.data['data']] 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:14,代码来源:test_event_get.py

示例7: __init__

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def __init__(self, options):
        super(Importer, self).__init__()
        self.options = options

        importer_langs = set(self.supported_languages)
        configured_langs = set(l[0] for l in settings.LANGUAGES)
        # Intersection is all the languages possible for the importer to use.
        self.languages = {}
        for lang_code in importer_langs & configured_langs:
            # FIXME: get language name translations from Django
            lang_obj, _ = Language.objects.get_or_create(id=lang_code)
            self.languages[lang_code] = lang_obj

        self.target_srid = settings.PROJECTION_SRID
        gps_srs = SpatialReference(4326)
        target_srs = SpatialReference(self.target_srid)
        if getattr(settings, 'BOUNDING_BOX'):
            self.bounding_box = Polygon.from_bbox(settings.BOUNDING_BOX)
            self.bounding_box.srid = self.target_srid
            target_to_gps_ct = CoordTransform(target_srs, gps_srs)
            self.bounding_box.transform(target_to_gps_ct)
        else:
            self.bounding_box = None
        self.gps_to_target_ct = CoordTransform(gps_srs, target_srs)

        self.setup()

        # this has to be run after setup, as it relies on organization and data source being set
        self._images = {obj.url: obj for obj in Image.objects.filter(publisher=self.organization,
                                                                     data_source=self.data_source)} 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:32,代码来源:base.py

示例8: start_serialization

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def start_serialization(self):
        self._init_options()
        self._cts = {}  # cache of CoordTransform's
        self.stream.write(
            '{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:%d"}},'
            ' "features": [' % self.srid) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:8,代码来源:geojson.py

示例9: handle

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def handle(self, *args, **options):
        """
        Import practice eastings and northings, from HSCIC data.
        """
        if not options["filename"]:
            print("Please supply a filename")
        else:
            self.IS_VERBOSE = False
            if options["verbosity"] > 1:
                self.IS_VERBOSE = True

            gridall = csv.reader(open(options["filename"], "rU"))
            postcodes = {}
            for row in gridall:
                postcode = row[1].replace(" ", "").strip()
                postcodes[postcode] = [row[36], row[37]]

            wgs84 = SpatialReference(4326)
            bng = SpatialReference(27700)
            trans = CoordTransform(bng, wgs84)

            practices = Practice.objects.filter(postcode__isnull=False).reverse()
            for practice in practices:
                practice.location = None
                postcode = practice.postcode.replace(" ", "").strip()
                if postcode in postcodes:
                    lng = postcodes[postcode][0]
                    lat = postcodes[postcode][1]
                    if lng and lat:
                        pnt = Point(int(lng), int(lat), srid=27700)
                        pnt.transform(trans)
                        practice.location = pnt
                practice.save() 
开发者ID:ebmdatalab,项目名称:openprescribing,代码行数:35,代码来源:geocode_practices.py

示例10: __call__

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def __call__(self, geometry):
        if geometry is None:
            return "null"
        if geometry.srid != self.srid:
            if geometry.srid not in self._transforms:
                srs = SpatialReference(self.srid)
                self._transforms[geometry.srid] = CoordTransform(geometry.srs, srs)
            geometry.transform(self._transforms[geometry.srid])
        return geometry.geojson 
开发者ID:ebmdatalab,项目名称:openprescribing,代码行数:11,代码来源:geojson_serializer.py

示例11: transform

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import CoordTransform [as 别名]
def transform(self, ct, clone=False):
        """
        Requires GDAL. Transform the geometry according to the given
        transformation object, which may be an integer SRID, and WKT or
        PROJ.4 string. By default, transform the geometry in-place and return
        nothing. However if the `clone` keyword is set, don't modify the
        geometry and return a transformed clone instead.
        """
        srid = self.srid

        if ct == srid:
            # short-circuit where source & dest SRIDs match
            if clone:
                return self.clone()
            else:
                return

        if isinstance(ct, gdal.CoordTransform):
            # We don't care about SRID because CoordTransform presupposes
            # source SRS.
            srid = None
        elif srid is None or srid < 0:
            raise GEOSException("Calling transform() with no SRID set is not supported")

        # Creating an OGR Geometry, which is then transformed.
        g = gdal.OGRGeometry(self._ogr_ptr(), srid)
        g.transform(ct)
        # Getting a new GEOS pointer
        ptr = g._geos_ptr()
        if clone:
            # User wants a cloned transformed geometry returned.
            return GEOSGeometry(ptr, srid=g.srid)
        if ptr:
            # Reassigning pointer, and performing post-initialization setup
            # again due to the reassignment.
            capi.destroy_geom(self.ptr)
            self.ptr = ptr
            self._post_init()
            self.srid = g.srid
        else:
            raise GEOSException('Transformed WKB was invalid.')

    # #### Topology Routines #### 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:45,代码来源:geometry.py


注:本文中的django.contrib.gis.gdal.CoordTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。