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


Python geos.Polygon方法代码示例

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


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

示例1: find

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def find(self, bbox=None, text=None, adm1=None, adm2=None, is_primary=True, threshold=0.5, srid=4326):
        qset = self.get_query_set().filter(is_primary=is_primary)
        if bbox:
            (minx, miny, maxx, maxy) = bbox
            bbox = Polygon(((minx,miny),(minx,maxy),(maxx,maxy),(maxx,miny),(minx,miny)),srid=srid)
            if srid != 4326: bbox.transform(4326) # convert to lon/lat
            qset = qset.filter(geometry__bboverlaps=bbox)
        if text:
            self.set_threshold(threshold)
            # use the pg_trgm index
            qset = qset.extra(select={"similarity":"similarity(preferred_name, %s)"},
                              select_params=[text],
                              where=["preferred_name %% %s"],
                              params=[text],
                              order_by=["-similarity"])
        if adm1: qset = qset.filter(admin1__exact=adm1)
        if adm2: qset = qset.filter(admin2__exact=adm2)
        return qset 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:20,代码来源:models.py

示例2: tile

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def tile(self, lonlat, zoom):
        """
        Returns a Polygon  corresponding to the region represented by a fictional
        Google Tile for the given longitude/latitude pair and zoom level. This
        tile is used to determine the size of a tile at the given point.
        """
        # The given lonlat is the center of the tile.
        delta = self._tilesize / 2

        # Getting the pixel coordinates corresponding to the
        # the longitude/latitude.
        px = self.lonlat_to_pixel(lonlat, zoom)

        # Getting the lower-left and upper-right lat/lon coordinates
        # for the bounding box of the tile.
        ll = self.pixel_to_lonlat((px[0] - delta, px[1] - delta), zoom)
        ur = self.pixel_to_lonlat((px[0] + delta, px[1] + delta), zoom)

        # Constructing the Polygon, representing the tile and returning.
        return Polygon(LinearRing(ll, (ll[0], ur[1]), ur, (ur[0], ll[1]), ll), srid=4326) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:zoom.py

示例3: create_country

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def create_country(name=None, fips='TT', gmi='TT', iso2='TT', iso3='TST', iso_num=0, border=None, effective=None):
    """Creates a country data model for unit testing

    :returns: The file model
    :rtype: :class:`storage.models.CountryData`
    """
    if not name:
        global COUNTRY_NAME_COUNTER
        name = 'test-country-%i' % COUNTRY_NAME_COUNTER
        COUNTRY_NAME_COUNTER += 1
    if not border:
        border = geos.Polygon(((0, 0), (0, 10), (10, 10), (10, 0), (0, 0)))
    if not effective:
        effective = timezone.now()

    return CountryData.objects.create(name=name, fips=fips, gmi=gmi, iso2=iso2, iso3=iso3, iso_num=iso_num,
                                      border=border, effective=effective) 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:utils.py

示例4: test_country_data

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def test_country_data(self):
        """Tests adding a border and country intersection calculation."""
        testborder = geos.Polygon(((0, 0), (0, 10), (10, 10), (10, 0), (0, 0)))
        testborder2 = geos.Polygon(((11, 0), (11, 8), (19, 8), (19, 0), (11, 0)))
        testborder3 = geos.Polygon(((11, 11), (11, 15), (15, 15), (15, 11), (11, 11)))
        testeffective = datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=utc)
        CountryData.objects.create(name='Test Country', fips='TC', gmi='TCY', iso2='TC', iso3='TCY', iso_num=42,
                                   border=testborder, effective=testeffective)
        CountryData.objects.create(name='Test Country 2', fips='TT', gmi='TCT', iso2='TT', iso3='TCT', iso_num=43,
                                   border=testborder2, effective=testeffective)
        CountryData.objects.create(name='Test Country 3', fips='TH', gmi='TCH', iso2='TH', iso3='TCH', iso_num=44,
                                   border=testborder3, effective=testeffective)
        ws = storage_test_utils.create_workspace(name='test', base_url='http://localhost')
        scale_file = storage_test_utils.create_file(file_name='test.txt', workspace=ws)
        with transaction.atomic():
            scale_file.geometry = geos.Polygon(((5, 5), (5, 10), (12, 10), (12, 5), (5, 5)))
            scale_file.set_countries()
            scale_file.save()
        tmp = [c.iso2 for c in scale_file.countries.all()]
        self.assertEqual(len(tmp), 2)
        self.assertIn('TC', tmp)
        self.assertIn('TT', tmp) 
开发者ID:ngageoint,项目名称:scale,代码行数:24,代码来源:test_models.py

示例5: extent_polygon

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def extent_polygon(self):
        """
            Convert extent into something more useful--a simple geos polygon
        """
        try:
            # This seems to raise if no rows exist
            extent = self.extent()
        except:
            return None
        bounds = Polygon((
            (extent[0], extent[1]),
            (extent[0], extent[3]),
            (extent[2], extent[3]),
            (extent[2], extent[1]),
            (extent[0], extent[1]),
        ))
        return bounds 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:19,代码来源:geo_inheritance_manager.py

示例6: chop_geom

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def chop_geom(multipolygon, fraction):
    """
        Transforms each point fraction the distance to the geometry's centroid to form a smaller geometry
    :param geom:
    :return: a multipolygon reduced by the fraction from the original
    """

    def transform_polygon(polygon):
        def transform_linear_ring(linear_ring):
            centroid = polygon.centroid
            return LinearRing(
                map(lambda point: to_tuple(LineString((point, centroid)).interpolate(fraction, normalized=True)),
                    linear_ring))

        linear_rings = map(lambda linear_ring: transform_linear_ring(linear_ring), polygon)
        if len(linear_rings) > 1:
            return Polygon(linear_rings[0], [linear_rings[1:]])
        else:
            return Polygon(linear_rings[0], [])

    return MultiPolygon(map(lambda polygon: transform_polygon(polygon), multipolygon)) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:23,代码来源:utils.py

示例7: test_alter_geom_field_dim

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def test_alter_geom_field_dim(self):
        Neighborhood = self.current_state.apps.get_model('gis', 'Neighborhood')
        p1 = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)))
        Neighborhood.objects.create(name='TestDim', geom=MultiPolygon(p1, p1))
        # Add 3rd dimension.
        self.alter_gis_model(
            migrations.AlterField, 'Neighborhood', 'geom', False,
            fields.MultiPolygonField, field_class_kwargs={'srid': 4326, 'dim': 3}
        )
        self.assertTrue(Neighborhood.objects.first().geom.hasz)
        # Rewind to 2 dimensions.
        self.alter_gis_model(
            migrations.AlterField, 'Neighborhood', 'geom', False,
            fields.MultiPolygonField, field_class_kwargs={'srid': 4326, 'dim': 2}
        )
        self.assertFalse(Neighborhood.objects.first().geom.hasz) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_operations.py

示例8: administrative_division

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def administrative_division(administrative_division_type, municipality):
    division = AdministrativeDivision.objects.create(
        name_en='test division',
        type=administrative_division_type,
        ocd_id='ocd-division/test:1',
        municipality=municipality,
    )
    coords = ((0, 0), (0, 200), (200, 200), (200, 0), (0, 0))
    AdministrativeDivisionGeometry.objects.create(division=division, boundary=MultiPolygon([Polygon(coords)]))
    return division 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:12,代码来源:conftest.py

示例9: administrative_division2

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def administrative_division2(administrative_division_type):
    division = AdministrativeDivision.objects.create(
        name_en='test division 2',
        type=administrative_division_type,
        ocd_id='ocd-division/test:2'
    )
    coords = ((100, 100), (100, 300), (300, 300), (300, 100), (100, 100))
    AdministrativeDivisionGeometry.objects.create(division=division, boundary=MultiPolygon([Polygon(coords)]))
    return division 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:11,代码来源:conftest.py

示例10: write

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def write(self, geom):
        "Return 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 memoryview(wkb) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:io.py

示例11: write_hex

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def write_hex(self, geom):
        "Return 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. 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:14,代码来源:io.py

示例12: setUp

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def setUp(self):
        django.setup()
        self.testborder = geos.Polygon(((0, 0), (0, 10), (10, 10), (0, 10), (0, 0)))
        self.testeffective = datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=utc)
        CountryData.objects.create(name='Test Country', fips='TC', gmi='TCY', iso2='TC', iso3='TCY', iso_num=42,
                                   border=self.testborder, effective=self.testeffective) 
开发者ID:ngageoint,项目名称:scale,代码行数:8,代码来源:test_models.py

示例13: test_border_update

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def test_border_update(self):
        newborder = geos.Polygon(((0, 0), (42, 0), (42, 42), (0, 42), (0, 0)))
        neweffective = datetime.datetime(2010, 4, 5, 18, 26, 0, tzinfo=utc)
        CountryData.objects.update_border('Test Country', newborder, neweffective)
        tmp = CountryData.objects.filter(name='Test Country', effective=neweffective)
        self.assertEqual(tmp[0].border, newborder)
        self.assertEqual(tmp[0].effective, neweffective)
        self.assertEqual(tmp[0].fips, 'TC') 
开发者ID:ngageoint,项目名称:scale,代码行数:10,代码来源:test_models.py

示例14: test_border_update_not_found

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def test_border_update_not_found(self):
        newborder = geos.Polygon(((0, 0), (42, 0), (42, 42), (0, 42), (0, 0)))
        self.assertRaises(CountryData.DoesNotExist, CountryData.objects.update_border, 'Kerblekistan', newborder) 
开发者ID:ngageoint,项目名称:scale,代码行数:5,代码来源:test_models.py

示例15: reassign_spatial_geometry

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import Polygon [as 别名]
def reassign_spatial_geometry(instance):
    coords = list(instance.geometry.coords)
    if type(coords[0]) == float:
        coords = [coords]
    else:
        while (type(coords[0][0]) != float):
            coords = coords[0]
        coords = [list(x) for x in coords]
    for point in coords:
        if point[0] >= -180 and point[0] <= 180:
            return
    while coords[0][0] < -180:
        for point in coords:
            point[0] += 360
    while coords[0][0] > 180:
        for point in coords:
            point[0] -= 360
    geometry = []
    for point in coords:
        latlng = [point[0], point[1]]
        geometry.append(tuple(latlng))
    if len(geometry) > 1:
        if geometry[0] == geometry[-1]:
            instance.geometry = dumps(Polygon(geometry))
        else:
            instance.geometry = dumps(LineString(geometry))
    else:
        instance.geometry = dumps(Point(geometry)) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:30,代码来源:models.py


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