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


Python gdal.SpatialReference方法代码示例

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


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

示例1: import_shapes

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def import_shapes(shapefile_path, logger):
    srs = SpatialReference(srs_wkt)
    lm = LayerMapping(
        Parcel,
        shapefile_path, {
            "shape_leng": "SHAPE_Leng",
            "shape_area": "SHAPE_Area",
            "map_par_id": "MAP_PAR_ID",
            "loc_id": "LOC_ID",
            "poly_type": "POLY_TYPE",
            "map_no": "MAP_NO",
            "source": "SOURCE",
            "plan_id": "PLAN_ID",
            "last_edit": "LAST_EDIT",
            "town_id": "TOWN_ID",
            "shape": "POLYGON"
        },
        source_srs=srs)
    lm.save(strict=True) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:21,代码来源:somervillema.py

示例2: test_custom_srid

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [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 SpatialReference [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: srs

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def srs(self):
        """
        Returns a GDAL SpatialReference object, if GDAL is installed.
        """
        if gdal.HAS_GDAL:
            # TODO: Is caching really necessary here?  Is complexity worth it?
            if hasattr(self, '_srs'):
                # Returning a clone of the cached SpatialReference object.
                return self._srs.clone()
            else:
                # Attempting to cache a SpatialReference object.

                # Trying to get from WKT first.
                try:
                    self._srs = gdal.SpatialReference(self.wkt)
                    return self.srs
                except Exception as msg:
                    pass

                try:
                    self._srs = gdal.SpatialReference(self.proj4text)
                    return self.srs
                except Exception as msg:
                    pass

                raise Exception('Could not get OSR SpatialReference from WKT: %s\nError:\n%s' % (self.wkt, msg))
        else:
            raise Exception('GDAL is not installed.') 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:models.py

示例5: get_units

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def get_units(cls, wkt):
        """
        Class method used by GeometryField on initialization to
        retrieve the units on the given WKT, without having to use
        any of the database fields.
        """
        if gdal.HAS_GDAL:
            return gdal.SpatialReference(wkt).units
        else:
            m = cls.units_regex.match(wkt)
            return m.group('unit'), m.group('unit_name') 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:models.py

示例6: get_spheroid

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def get_spheroid(cls, wkt, string=True):
        """
        Class method used by GeometryField on initialization to
        retrieve the `SPHEROID[..]` parameters from the given WKT.
        """
        if gdal.HAS_GDAL:
            srs = gdal.SpatialReference(wkt)
            sphere_params = srs.ellipsoid
            sphere_name = srs['spheroid']
        else:
            m = cls.spheroid_regex.match(wkt)
            if m:
                sphere_params = (float(m.group('major')), float(m.group('flattening')))
                sphere_name = m.group('name')
            else:
                return None

        if not string:
            return sphere_name, sphere_params
        else:
            # `string` parameter used to place in format acceptable by PostGIS
            if len(sphere_params) == 3:
                radius, flattening = sphere_params[0], sphere_params[2]
            else:
                radius, flattening = sphere_params
            return 'SPHEROID["%s",%s,%s]' % (sphere_name, radius, flattening) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:28,代码来源:models.py

示例7: wkt

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def wkt(self):
        if hasattr(self, 'srtext'):
            return self.srtext
        from django.contrib.gis.gdal import SpatialReference
        return SpatialReference(self.proj4text).wkt 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:models.py

示例8: _init_options

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def _init_options(self):
        super(Serializer, self)._init_options()
        self.geometry_field = self.json_kwargs.pop('geometry_field', None)
        self.srs = SpatialReference(self.json_kwargs.pop('srid', 4326)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:geojson.py

示例9: test_get_event_list_verify_bbox_filter

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [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

示例10: __init__

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [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

示例11: srs

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def srs(self):
        "Return the OSR SpatialReference for SRID of this Geometry."
        if self.srid:
            try:
                return gdal.SpatialReference(self.srid)
            except gdal.SRSException:
                pass
        return None 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:10,代码来源:geometry.py

示例12: srs

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def srs(self):
        "Returns the OSR SpatialReference for SRID of this Geometry."
        if not gdal.HAS_GDAL:
            raise GEOSException('GDAL required to return a SpatialReference object.')
        if self.srid:
            try:
                return gdal.SpatialReference(self.srid)
            except gdal.SRSException:
                pass
        return None 
开发者ID:drexly,项目名称:openhgsenti,代码行数:12,代码来源:geometry.py

示例13: test_gdal

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [as 别名]
def test_gdal(self):
        "Testing `ogr` and `srs` properties."
        g1 = fromstr('POINT(5 23)')
        self.assertIsInstance(g1.ogr, gdal.OGRGeometry)
        self.assertIsNone(g1.srs)

        g1_3d = fromstr('POINT(5 23 8)')
        self.assertIsInstance(g1_3d.ogr, gdal.OGRGeometry)
        self.assertEqual(g1_3d.ogr.z, 8)

        g2 = fromstr('LINESTRING(0 0, 5 5, 23 23)', srid=4326)
        self.assertIsInstance(g2.ogr, gdal.OGRGeometry)
        self.assertIsInstance(g2.srs, gdal.SpatialReference)
        self.assertEqual(g2.hex, g2.ogr.hex)
        self.assertEqual('WGS 84', g2.srs.name) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:test_geos.py

示例14: handle

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [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

示例15: __call__

# 需要导入模块: from django.contrib.gis import gdal [as 别名]
# 或者: from django.contrib.gis.gdal import SpatialReference [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


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