python类Polygon()的实例源码

parking_areas.py 文件源码 项目:parkkihubi 作者: City-of-Helsinki 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _get_polygons(self, geom):
        """
        Turns the XML containing coordinates into a multipolygon
        """
        polygons = []
        for pos in geom.iter('*'):
            # get leaf nodes. Treat LinearRing and MultiSurface the same way
            if len(pos) == 0:
                positions = list(filter(None, pos.text.split(' ')))
                points = []
                points_as_pairs = zip(positions[1::2], positions[::2])
                for latitude, longitude in points_as_pairs:
                    points.append(Point(float(latitude), float(longitude)))
                polygons.append(Polygon(points))
        return MultiPolygon(polygons)
adapter.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid
adapter.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _fix_geometry_collection(self, coll):
        # Fix polygon orientations in geometry collections as described in
        # __init__()
        for i, geom in enumerate(coll):
            if isinstance(geom, Polygon):
                coll[i] = self._fix_polygon(geom)
adapter.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid
adapter.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _fix_geometry_collection(self, coll):
        # Fix polygon orientations in geometry collections as described in
        # __init__()
        for i, geom in enumerate(coll):
            if isinstance(geom, Polygon):
                coll[i] = self._fix_polygon(geom)
adapter.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid
adapter.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def _fix_geometry_collection(self, coll):
        # Fix polygon orientations in geometry collections as described in
        # __init__()
        for i, geom in enumerate(coll):
            if isinstance(geom, Polygon):
                coll[i] = self._fix_polygon(geom)
io.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def write(self, geom):
        "Returns the WKB representation of the given geometry."
        from django.contrib.gis.geos import Polygon
        geom = self._handle_empty_point(geom)
        wkb = wkb_writer_write(self.ptr, geom.ptr, byref(c_size_t()))
        if isinstance(geom, Polygon) and geom.empty:
            # Fix GEOS output for empty polygon.
            # See https://trac.osgeo.org/geos/ticket/680.
            wkb = wkb[:-8] + b'\0' * 4
        return six.memoryview(wkb)
io.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def write_hex(self, geom):
        "Returns the HEXEWKB representation of the given geometry."
        from django.contrib.gis.geos.polygon import Polygon
        geom = self._handle_empty_point(geom)
        wkb = wkb_writer_write_hex(self.ptr, geom.ptr, byref(c_size_t()))
        if isinstance(geom, Polygon) and geom.empty:
            wkb = wkb[:-16] + b'0' * 8
        return wkb

    # ### WKBWriter Properties ###

    # Property for getting/setting the byteorder.
adapter.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid
adapter.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _fix_geometry_collection(self, coll):
        # Fix polygon orientations in geometry collections as described in
        # __init__()
        for i, geom in enumerate(coll):
            if isinstance(geom, Polygon):
                coll[i] = self._fix_polygon(geom)
io.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def write(self, geom):
        "Returns the WKB representation of the given geometry."
        from django.contrib.gis.geos import Polygon
        geom = self._handle_empty_point(geom)
        wkb = wkb_writer_write(self.ptr, geom.ptr, byref(c_size_t()))
        if isinstance(geom, Polygon) and geom.empty:
            # Fix GEOS output for empty polygon.
            # See https://trac.osgeo.org/geos/ticket/680.
            wkb = wkb[:-8] + b'\0' * 4
        return six.memoryview(wkb)
io.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def write_hex(self, geom):
        "Returns the HEXEWKB representation of the given geometry."
        from django.contrib.gis.geos.polygon import Polygon
        geom = self._handle_empty_point(geom)
        wkb = wkb_writer_write_hex(self.ptr, geom.ptr, byref(c_size_t()))
        if isinstance(geom, Polygon) and geom.empty:
            wkb = wkb[:-16] + b'0' * 8
        return wkb

    # ### WKBWriter Properties ###

    # Property for getting/setting the byteorder.
views.py 文件源码 项目:georef 作者: rukayaj 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def import_shp(request, shp_name):
    from django.contrib.gis.gdal import DataSource
    root = 'C:\\Users\\JohaadienR\\Documents\\Projects\\python-sites\\georef-data-sources\\planetgis\\'

    # Keep track of all the layers we are adding in
    layers = ['District Municipalities 2016.kml',
              'Local Municipalities 2016.kml',
              'Wards 2016.kml',
              'Main Places.kml',
              'Sub Places.kml']

    for layer_name in layers:
        ds = DataSource(root + layer_name)
        for item in ds[0]:
            # Get name and location from layer
            locality_name = item.get('Name')
            try:
                polygon = Polygon(item.geom.coords[1][0])
            except GEOSException:
                continue

            # Get/create the geographical position, locality name and importer profile
            gp, created = models.GeographicalPosition.objects.get_or_create(polygon=polygon, precision_m=0)
            ln, created = models.LocalityName.objects.get_or_create(locality_name=locality_name)
            au, created = models.Profile.objects.get_or_create(name='Surveyor General')

            # Get/create the georeference using the above
            models.GeoReference.objects.get_or_create(locality_name=ln, geographical_position=gp, author=au)
adapter.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid
adapter.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _fix_geometry_collection(self, coll):
        # Fix polygon orientations in geometry collections as described in
        # __init__()
        for i, geom in enumerate(coll):
            if isinstance(geom, Polygon):
                coll[i] = self._fix_polygon(geom)
views.py 文件源码 项目:imagery 作者: cenima-ibama 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def filter_bbox(self, queryset, value):
        bbox = [float(coord) for coord in value.split(',')]
        bbox = Polygon((
            bbox[:2],
            [bbox[0], bbox[3]],
            bbox[2:],
            [bbox[2], bbox[1]],
            bbox[:2]
        ))
        return queryset.filter(geom__intersects=bbox)
models.py 文件源码 项目:imagery 作者: cenima-ibama 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create_scene(self):
        """Get or Create a new Scene object for this path and row."""
        scene_date = calendar_date(
            self.next_scene_name()[9:13],
            self.next_scene_name()[13:16]
            )

        try:
            geom = Polygon(get_bounds(self.next_scene_name()))
        except IndexError:
            geom = None

        try:
            cloud_rate = get_cloud_rate(self.next_scene_name())
        except FileNotFoundError:
            cloud_rate = None

        return Scene.objects.get_or_create(
            path=self.path,
            row=self.row,
            sat='L8',
            name=self.next_scene_name(),
            date=scene_date,
            status='downloading',
            geom=geom,
            cloud_rate=cloud_rate
            )
test_models.py 文件源码 项目:imagery 作者: cenima-ibama 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_download(self):
        # mock creation_date to 2015-01-01, so we will have a correct date
        # to download a new scene
        self.sd.creation_date = date(2015, 1, 1)
        self.sd.save()

        downloaded = self.sd.download_new_scene([10, 11])
        self.assertEqual(len(downloaded), 2)

        scene = Scene.objects.get(name='LC82200662015017LGN00')
        self.assertIsInstance(scene, Scene)
        bounds = Polygon(((-45.4508, -7.62855), (-43.75824, -7.98923),
            (-44.12919, -9.73044), (-45.82968, -9.36601), (-45.4508, -7.62855)))
        self.assertEqual(scene.cloud_rate, 65.28)
        self.assertEqual(scene.geom, bounds)
        self.assertEqual(scene.status, 'downloading')

        self.assertIsInstance(
            Image.objects.get(name='LC82200662015017LGN00_B10.TIF'),
            Image
            )
        self.assertIsInstance(
            Image.objects.get(name='LC82200662015017LGN00_B11.TIF'),
            Image
            )

        self.assertEqual(self.sd.check_last_scene([10, 11]), [])
        self.assertEqual(self.sd.last_scene().status, 'downloaded')

        downloaded = self.sd.check_last_scene([10, 11, 'BQA'])
        self.assertEqual(len(downloaded), 3)
        self.assertIsInstance(
            Image.objects.get(name='LC82200662015017LGN00_BQA.TIF'),
            Image
            )
        rmtree(downloaded[2][0].replace('/LC82200662015017LGN00_BQA.TIF', ''))

        self.assertEqual(self.sd2.download_new_scene(['BQA']), [])
test_views.py 文件源码 项目:imagery 作者: cenima-ibama 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_geo_scene_pagination_response(self):

        for i in range(1,21):
            Scene.objects.create(
                path='001',
                row='001',
                sat='L8',
                date=date(2015, 2, 2),
                name='LC80010012015001LGN'.join("%02d" % i ),
                cloud_rate=21.9,
                status='downloading',
                geom=Polygon(
                    [
                        [-54.159229, -11.804765], [-56.405499, -11.291305],
                        [-55.990002, -9.499491], [-53.755329, -10.006503],
                        [-54.159229, -11.804765]
                    ])
                )

        self.assertEqual(Scene.objects.count(), 22)

        response = client.get(reverse('geoscene-listview'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data.get('features')), 20)

        response = client.get(reverse('geoscene-listview'), {'page': 2})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data.get('features')), 2)


问题


面经


文章

微信
公众号

扫码关注公众号