• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python geometry.from_wkt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygeoif.geometry.from_wkt函数的典型用法代码示例。如果您正苦于以下问题:Python from_wkt函数的具体用法?Python from_wkt怎么用?Python from_wkt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_multipolygon

 def test_multipolygon(self):
     p = geometry.from_wkt(
         "MULTIPOLYGON(((0 0,10 20,30 40,0 0)," "(1 1,2 2,3 3,1 1))," "((100 100,110 110,120 120,100 100)))"
     )
     # two polygons: the first one has an interior ring
     self.assertEqual(len(p.geoms), 2)
     self.assertEqual(p.geoms[0].exterior.coords, ((0.0, 0.0), (10.0, 20.0), (30.0, 40.0), (0.0, 0.0)))
     self.assertEqual(list(p.geoms[0].interiors)[0].coords, ((1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (1.0, 1.0)))
     self.assertEqual(p.geoms[1].exterior.coords, ((100.0, 100.0), (110.0, 110.0), (120.0, 120.0), (100.0, 100.0)))
     self.assertEqual(
         p.to_wkt(),
         "MULTIPOLYGON(((0.0 0.0, 10.0 20.0, "
         "30.0 40.0, 0.0 0.0),"
         "(1.0 1.0, 2.0 2.0, 3.0 3.0, 1.0 1.0))"
         "((100.0 100.0, 110.0 110.0,"
         " 120.0 120.0, 100.0 100.0)))",
     )
     p = geometry.from_wkt("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1)," "(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))")
     self.assertEqual(len(p.geoms), 2)
     p = geometry.from_wkt("MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20))," "((15 5, 40 10, 10 20, 5 10, 15 5)))")
     self.assertEqual(
         p.__geo_interface__,
         {
             "type": "MultiPolygon",
             "bbox": (5.0, 5.0, 45.0, 40.0),
             "coordinates": (
                 (((30.0, 20.0), (10.0, 40.0), (45.0, 40.0), (30.0, 20.0)),),
                 (((15.0, 5.0), (40.0, 10.0), (10.0, 20.0), (5.0, 10.0), (15.0, 5.0)),),
             ),
         },
     )
开发者ID:benjwadams,项目名称:pygeoif,代码行数:31,代码来源:test_main.py


示例2: test_polygon

 def test_polygon(self):
     p = geometry.from_wkt(
         "POLYGON((-91.611 76.227,-91.543 76.217,"
         "-91.503 76.222,-91.483 76.221,-91.474 76.211,"
         "-91.484 76.197,-91.512 76.193,-91.624 76.2,"
         "-91.638 76.202,-91.647 76.211,-91.648 76.218,"
         "-91.643 76.221,-91.636 76.222,-91.611 76.227))"
     )
     self.assertEqual(p.exterior.coords[0][0], -91.611)
     self.assertEqual(p.exterior.coords[0], p.exterior.coords[-1])
     self.assertEqual(len(p.exterior.coords), 14)
     p = geometry.from_wkt("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, " "3 3, 2 3,2 2))")
     self.assertEqual(p.exterior.coords[0], p.exterior.coords[-1])
     self.assertEqual(p.exterior.coords[0], (1.0, 1.0))
     self.assertEqual(len(list(p.interiors)), 1)
     self.assertEqual(list(p.interiors)[0].coords, ((2.0, 2.0), (3.0, 2.0), (3.0, 3.0), (2.0, 3.0), (2.0, 2.0)))
     self.assertEqual(
         p.to_wkt(),
         "POLYGON((1.0 1.0, 5.0 1.0, 5.0 5.0, "
         "1.0 5.0, 1.0 1.0),(2.0 2.0, 3.0 2.0, "
         "3.0 3.0, 2.0 3.0, 2.0 2.0))",
     )
     p = geometry.from_wkt("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))")
     self.assertEqual(p.exterior.coords[0], p.exterior.coords[-1])
     p = geometry.from_wkt(
         """POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),
         (20 30, 35 35, 30 20, 20 30))"""
     )
     self.assertEqual(p.exterior.coords[0], p.exterior.coords[-1])
开发者ID:benjwadams,项目名称:pygeoif,代码行数:29,代码来源:test_main.py


示例3: test_multilinestring

 def test_multilinestring(self):
     p = geometry.from_wkt('MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))')
     self.assertEqual(p.geoms[0].coords, (((3, 4),(10, 50),(20, 25))))
     self.assertEqual(p.geoms[1].coords, (((-5, -8),(-10, -8),(-15, -4))))
     self.assertEqual(p.to_wkt(),'MULTILINESTRING((3.0 4.0, 10.0 50.0, 20.0 25.0),(-5.0 -8.0, -10.0 -8.0, -15.0 -4.0))')
     p = geometry.from_wkt('''MULTILINESTRING ((10 10, 20 20, 10 40),
         (40 40, 30 30, 40 20, 30 10))''')
开发者ID:karimbahgat,项目名称:Tably,代码行数:7,代码来源:test_main.py


示例4: test_multipolygon

 def test_multipolygon(self):
     p = geometry.from_wkt('MULTIPOLYGON(((0 0,10 20,30 40,0 0),(1 1,2 2,3 3,1 1)),((100 100,110 110,120 120,100 100)))')
     #two polygons: the first one has an interior ring
     self.assertEqual(len(p.geoms), 2)
     self.assertEqual(p.geoms[0].exterior.coords,
             ((0.0, 0.0), (10.0, 20.0) , (30.0, 40.0), (0.0, 0.0)))
     self.assertEqual(list(p.geoms[0].interiors)[0].coords,
             ((1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (1.0, 1.0)))
     self.assertEqual(p.geoms[1].exterior.coords,
         ((100.0, 100.0), (110.0, 110.0), (120.0, 120.0), (100.0, 100.0)))
     self.assertEqual(p.to_wkt(),
         'MULTIPOLYGON(((0.0 0.0, 10.0 20.0, 30.0 40.0, 0.0 0.0),(1.0 1.0, 2.0 2.0, 3.0 3.0, 1.0 1.0))((100.0 100.0, 110.0 110.0, 120.0 120.0, 100.0 100.0)))')
     p = geometry.from_wkt('MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))')
     self.assertEqual(len(p.geoms), 2)
开发者ID:mlaloux,项目名称:pygeoif,代码行数:14,代码来源:test_main.py


示例5: test_multipoint

 def test_multipoint(self):
     p = geometry.from_wkt("MULTIPOINT(3.5 5.6,4.8 10.5)")
     self.assertEqual(isinstance(p, geometry.MultiPoint), True)
     self.assertEqual(p.geoms[0].x, 3.5)
     self.assertEqual(p.geoms[1].y, 10.5)
     self.assertEqual(p.to_wkt(), "MULTIPOINT(3.5 5.6, 4.8 10.5)")
     p = geometry.from_wkt("MULTIPOINT ((10 40), (40 30), " "(20 20), (30 10))")
     self.assertEqual(isinstance(p, geometry.MultiPoint), True)
     self.assertEqual(p.geoms[0].x, 10.0)
     self.assertEqual(p.geoms[3].y, 10.0)
     p = geometry.from_wkt("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
     self.assertEqual(isinstance(p, geometry.MultiPoint), True)
     self.assertEqual(p.geoms[0].x, 10.0)
     self.assertEqual(p.geoms[3].y, 10.0)
开发者ID:benjwadams,项目名称:pygeoif,代码行数:14,代码来源:test_main.py


示例6: test_linestring

 def test_linestring(self):
     l = geometry.from_wkt('LINESTRING(-72.991 46.177,-73.079 46.16,'
                           '-73.146 46.124,-73.177 46.071,-73.164 46.044)')
     self.assertEqual(l.to_wkt(), 'LINESTRING (-72.991 46.177, '
                                  '-73.079 46.16, -73.146 46.124, '
                                  '-73.177 46.071, -73.164 46.044)')
     self.assertEqual(isinstance(l, geometry.LineString), True)
开发者ID:cleder,项目名称:pygeoif,代码行数:7,代码来源:test_main.py


示例7: create_leaflet_viewer

    def create_leaflet_viewer(self, idaho_image_results, output_filename):
        '''Create a leaflet viewer html file for viewing idaho images

        Args:
            idaho_image_results (dict): IDAHO image result set as returned from 
                                        the catalog.
            output_filename (str): where to save an output html file
        '''

        description = self.describe_images(idaho_image_results)
        if len(description) > 0:
            functionstring = ''
            for catid, images in description.items():
                for partnum, part in images['parts'].items():
    
                    num_images = len(list(part.keys()))
                    partname = None
                    if num_images == 1:
                        # there is only one image, use the PAN
                        partname = [p for p in list(part.keys())][0]
                        pan_image_id = ''
                    elif num_images == 2:
                        # there are two images in this part, use the multi (or pansharpen)
                        partname = [p for p in list(part.keys()) if p is not 'PAN'][0]
                        pan_image_id = part['PAN']['id']
    
                    if not partname:
                        self.logger.debug("Cannot find part for idaho image.")
                        continue
    
                    bandstr = {
                        'RGBN': '0,1,2',
                        'WORLDVIEW_8_BAND': '4,2,1',
                        'PAN': '0'
                    }.get(partname, '0,1,2')
    
                    part_boundstr_wkt = part[partname]['boundstr']
                    part_polygon = geometry.from_wkt(part_boundstr_wkt)
                    bucketname = part[partname]['bucket']
                    image_id = part[partname]['id']
                    W, S, E, N = part_polygon.bounds
    
                    functionstring += "addLayerToMap('%s','%s',%s,%s,%s,%s,'%s');\n" % (bucketname, image_id, W,S,E,N, pan_image_id)
    
            __location__ = os.path.realpath(
                os.path.join(os.getcwd(), os.path.dirname(__file__)))
            with open(os.path.join(__location__, 'leafletmap_template.html'), 'r') as htmlfile:
                data=htmlfile.read().decode("utf8")
    
            data = data.replace('FUNCTIONSTRING',functionstring)
            data = data.replace('CENTERLAT',str(S))
            data = data.replace('CENTERLON',str(W))
            data = data.replace('BANDS',bandstr)
            data = data.replace('TOKEN',self.gbdx_connection.access_token)
    
            with codecs.open(output_filename,'w','utf8') as outputfile:
                self.logger.debug("Saving %s" % output_filename)
                outputfile.write(data)
        else:
            print("No items returned.")
开发者ID:jeffnaus,项目名称:gbdxtools,代码行数:60,代码来源:idaho.py


示例8: get_bounding_box

def get_bounding_box(wkt):
    geom = geometry.from_wkt(wkt)
    minx = geom.bounds[0]
    miny = geom.bounds[1]
    maxx = geom.bounds[2]
    maxy = geom.bounds[3]
    return str(minx) + ',' + str(miny) + ',' + str(maxx) + ',' + str(maxy)
开发者ID:bcdev,项目名称:GISportal,代码行数:7,代码来源:geometry_support.py


示例9: test_geometrycollection

 def test_geometrycollection(self):
     gc = geometry.from_wkt('GEOMETRYCOLLECTION(POINT(4 6), LINESTRING(4 6,7 10))')
     self.assertEqual(len(list(gc.geoms)), 2)
     self.assertTrue(isinstance(list(gc.geoms)[0], geometry.Point))
     self.assertTrue(isinstance(list(gc.geoms)[1], geometry.LineString))
     self.assertEqual(gc.to_wkt(),
         'GEOMETRYCOLLECTION (POINT (4.0 6.0), LINESTRING (4.0 6.0, 7.0 10.0))')
开发者ID:karimbahgat,项目名称:Tably,代码行数:7,代码来源:test_main.py


示例10: verify_wkt

def verify_wkt(data):
    try:
        from shapely import wkt
        geom = wkt.loads(data)
    except ImportError:
        from pygeoif.geometry import from_wkt
        geom = from_wkt(data)
    return geom
开发者ID:seantis,项目名称:seantis.dir.events,代码行数:8,代码来源:utils.py


示例11: wkt

	def wkt(self, data):
		if data is None or len(data) == 0:
			return False

		try:
			wkt = geometry.from_wkt(data)
			return isinstance(wkt, geometry._Geometry)
		except:
			return False
开发者ID:JanVan01,项目名称:gwot-physical,代码行数:9,代码来源:utils.py


示例12: verifyWkt

 def verifyWkt(self, data):
     try:
         from shapely import wkt
         geom = wkt.loads(data)
         #geom = {"type":"Point","coordinates":"00000000"}
     except ImportError:
         from pygeoif.geometry import from_wkt
         geom = from_wkt(data)
     return geom
开发者ID:robystar,项目名称:collective.geo.contentlocations,代码行数:9,代码来源:geoshapeform.py


示例13: test_point

 def test_point(self):
     p = geometry.from_wkt("POINT (0.0 1.0)")
     self.assertEqual(isinstance(p, geometry.Point), True)
     self.assertEqual(p.x, 0.0)
     self.assertEqual(p.y, 1.0)
     self.assertEqual(p.to_wkt(), "POINT (0.0 1.0)")
     self.assertEqual(p.to_wkt(), p.wkt)
     self.assertEqual(str(p), "POINT (0.0 1.0)")
     self.assertEqual(p.geom_type, "Point")
开发者ID:benjwadams,项目名称:pygeoif,代码行数:9,代码来源:test_main.py


示例14: records_in_polygon

def records_in_polygon(records,polygon):
    # Filter out the records that are not inside the polygon
    output_records = []
    for record in records:
        recordwkt = record['properties']['footprintWkt']
        record_polygon = geometry.from_wkt(recordwkt)
        if bbox_in_poly(record_polygon,polygon):
            output_records.append(record)

    #print "Filtered in polygon: %s" % len(output_records)
    return output_records
开发者ID:loominator1970,项目名称:gbdxtools,代码行数:11,代码来源:catalog_search_aoi.py


示例15: query_iteratively

    def query_iteratively(self, searchAreaWkt, query, count=100, ttl='5m'):
        '''
        Perform a vector services query using the QUERY API
        (https://gbdxdocs.digitalglobe.com/docs/vs-query-list-vector-items-returns-default-fields)

        Args:
            searchAreaWkt: WKT Polygon of area to search
            query: Elastic Search query
            count: Maximum number of results to return
            ttl: Amount of time for each temporary vector page to exist

        Returns:
            generator of vector results
    
        '''

        search_area_polygon = geometry.from_wkt(searchAreaWkt)
        left, lower, right, upper = search_area_polygon.bounds

        params = {
            "q": query,
            "count": count,
            "ttl": ttl,
            "left": left,
            "right": right,
            "lower": lower,
            "upper": upper
        }

        # initialize paging request
        r = self.gbdx_connection.get(self.query_url, params=params)
        r.raise_for_status()
        page = r.json()
        paging_id = page['pagingId']
        item_count = int(page['itemCount'])

        # get vectors from each page
        while paging_id and item_count > 0:

          headers = {'Content-Type':'application/x-www-form-urlencoded'}
          data = {
              "pagingId": paging_id,
              "ttl": ttl
          }

          r = self.gbdx_connection.post(self.page_url, headers=headers, data=data)
          r.raise_for_status()
          page = r.json()
          paging_id = page['next_paging_id']
          item_count = int(page['item_count'])
          data = page['data']

          for vector in data:
            yield vector
开发者ID:michaelconnor00,项目名称:gbdxtools,代码行数:54,代码来源:vectors.py


示例16: coordinates

 def coordinates(self, value):
     if value:
         try:
             from shapely import wkt
             geom = wkt.loads(value)
         except ImportError:
             from pygeoif.geometry import from_wkt
             geom = from_wkt(value)
         coords = geom.__geo_interface__
         geo = IWriteGeoreferenced(self.context)
         geo.setGeoInterface(coords['type'], coords['coordinates'])
开发者ID:collective,项目名称:collective.geo.behaviour,代码行数:11,代码来源:behaviour.py


示例17: search_materials_in_multiple_small_searches

def search_materials_in_multiple_small_searches(search_request, gbdx_connection, base_url):
    D = 1.4  # the size in degrees of the side of a square that we will search

    searchAreaWkt = search_request['searchAreaWkt']
    searchAreaPolygon = geometry.from_wkt(searchAreaWkt)

    W, S, E, N = searchAreaPolygon.bounds
    Ys = [i for i in xfrange(S,N,D)]
    Xs = [i for i in xfrange(W,E,D)]

    # Handle point searches:
    if W == E and N == S:
        Ys = [S, N]
        Xs = [W, E]

    # print Xs
    # print Ys
    # print searchAreaWkt

    records = []
    # Loop pairwise
    row = 0
    col = 0
    for y, y1 in zip(Ys, Ys[1:]):
        row = row + 1
        for x, x1 in zip(Xs, Xs[1:]):
            col = col + 1
            bbox = (x, y, x1, y1)
            subsearchpoly = polygon_from_bounds(bbox)

            # # verify that the subsearchpoly is inside the searchAreaPolygon.  If not break.
            if not bbox_in_poly(subsearchpoly,searchAreaPolygon) and not bbox_in_poly(searchAreaPolygon, subsearchpoly) and not (y == y1 and x == x1):
                pass
            else:

                search_request['searchAreaWkt'] = subsearchpoly.wkt

                url = '%(base_url)s/search?includeRelationships=false' % {
                    'base_url': base_url
                }
                headers = {'Content-Type':'application/json'}
                r = gbdx_connection.post(url, headers=headers, data=json.dumps(search_request))
                r.raise_for_status()

                records = records + r.json()['results']

    records = dedup_records(records)

    # this next line works, but filters too much stuff.  It removes some items intersecting the polygon.
    #records = records_in_polygon(records, searchAreaPolygon)  # this takes quite a while to run, so leave it commented

    return records
开发者ID:michaelconnor00,项目名称:gbdxtools,代码行数:52,代码来源:catalog_search_aoi.py


示例18: exportKML

 def exportKML(self):
     k = kml.KML()
     ns = '{http://www.opengis.net/kml/2.2}'
     d = kml.Document(ns, '0', 'Export', 'Exported from Lowiki')
     k.append(d)
     f = kml.Folder(ns, '1', 'Locations', 'Locations in Lowiki')
     d.append(f)
     for page in self._get_export_pages():
         try:
             p = kml.Placemark(ns, str(page.id),
                               page.name, '')
             p.geometry = geometry.from_wkt(page.mapdata.geom.wkt)
             f.append(p)
         except:
             pass
     filename = '/tmp/export.kml'
     with open(filename, 'w') as f:
         f.write(k.to_string().encode('utf-8'))
         f.close()
     self.file = open(filename, 'r')
     self.file_mime_type = 'application/vnd.google-earth.kml+xml'
开发者ID:lowiki-org,项目名称:localwiki-backend-server,代码行数:21,代码来源:views.py


示例19: test_wkt_ok

 def test_wkt_ok(self):
     for wkt in self.wkt_ok:
         geometry.from_wkt(wkt)
开发者ID:benjwadams,项目名称:pygeoif,代码行数:3,代码来源:test_main.py


示例20: get_tms_layers

    def get_tms_layers(self,
                       catid,
                       bands='4,2,1',
                       gamma=1.3,
                       highcutoff=0.98,
                       lowcutoff=0.02,
                       brightness=1.0,
                       contrast=1.0):
        '''Get list of urls and bounding boxes corrsponding to idaho images for a given catalog id.

        Args:
           catid (str): Catalog id
           bands (str): Bands to display, separated by commas (0-7).
           gamma (float): gamma coefficient. This is for on-the-fly pansharpening.
           highcutoff (float): High cut off coefficient (0.0 to 1.0). This is for on-the-fly pansharpening.
           lowcutoff (float): Low cut off coefficient (0.0 to 1.0). This is for on-the-fly pansharpening.
           brightness (float): Brightness coefficient (0.0 to 1.0). This is for on-the-fly pansharpening.
           contrast (float): Contrast coefficient (0.0 to 1.0). This is for on-the-fly pansharpening.
        Returns:
           urls (list): TMS urls.
           bboxes (list of tuples): Each tuple is (W, S, E, N) where (W,S,E,N) are the bounds of the
                                    corresponding idaho part.
        '''

        description = self.describe_images(self.get_images_by_catid(catid))
        service_url = 'http://idaho.geobigdata.io/v1/tile/'

        urls, bboxes = [], []
        for catid, images in description.items():
            for partnum, part in images['parts'].items():
                if 'PAN' in part.keys():
                    pan_id = part['PAN']['id']
                if 'WORLDVIEW_8_BAND' in part.keys():
                    ms_id = part['WORLDVIEW_8_BAND']['id']
                    ms_partname = 'WORLDVIEW_8_BAND'
                elif 'RGBN' in part.keys():
                    ms_id = part['RGBN']['id']
                    ms_partname = 'RGBN'

                if ms_id:
                    if pan_id:
                        band_str = ms_id + '/{z}/{x}/{y}?bands=' + bands + '&panId=' + pan_id
                    else:
                        band_str = ms_id + '/{z}/{x}/{y}?bands=' + bands
                    bbox = geometry.from_wkt(part[ms_partname]['boundstr']).bounds
                elif not ms_id and pan_id:
                    band_str = pan_id + '/{z}/{x}/{y}?bands=0'
                    bbox = geometry.from_wkt(part['PAN']['boundstr']).bounds
                else:
                    continue

                bboxes.append(bbox)

                # Get the bucket. It has to be the same for all entries in the part.
                bucket = part[part.keys()[0]]['bucket']

                # Get the token
                token = self.gbdx_connection.access_token

                # Assemble url
                url = (service_url + bucket + '/'
                                   + band_str
                                   + """&gamma={}
                                        &highCutoff={}
                                        &lowCutoff={}
                                        &brightness={}
                                        &contrast={}
                                        &token={}""".format(gamma,
                                                            highcutoff,
                                                            lowcutoff,
                                                            brightness,
                                                            contrast,
                                                            token))
                urls.append(url)

        return urls, bboxes
开发者ID:michaelconnor00,项目名称:gbdxtools,代码行数:76,代码来源:idaho.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pygeoip.GeoIP类代码示例发布时间:2022-05-25
下一篇:
Python geometry.as_shape函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap