本文整理汇总了Python中shapely.geometry.asShape方法的典型用法代码示例。如果您正苦于以下问题:Python geometry.asShape方法的具体用法?Python geometry.asShape怎么用?Python geometry.asShape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry
的用法示例。
在下文中一共展示了geometry.asShape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_flickr_geojson
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def parse_flickr_geojson(flickr_file):
json_data = codecs.open(flickr_file, "r", "utf-8").read()
data = demjson.decode(json_data)
features = data['features']
for feature in features:
woe_id = str(feature['properties']['woe_id'])
name = feature['properties']['label']
if not name:
continue
feature_type = feature['properties']['place_type']
feature_code = str(feature['properties']['place_type_id'])
json_geometry = feature['geometry']
updated = "2011-01-08 00:00:00+00" #i.e. as from http://code.flickr.com/blog/2011/01/08/flickr-shapefiles-public-dataset-2-0/
geometry = asShape(json_geometry).wkt
out_line = ['F', woe_id, name, feature_type, feature_code, updated, geometry ]
print "\t".join(out_line)
return flickr_file
示例2: check_file
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def check_file(filename):
with collection(filename, 'r') as features:
for feature in features:
try:
shape = asShape(feature['geometry'])
if not shape.is_valid:
geometry = json.dumps(feature, indent=2)
print "Invalid geometry:\n"
print geometry
print '\n'
except:
print "Error parsing:\n"
print json.dumps(feature, indent=2)
示例3: chunk
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def chunk(featureFileName, sectionFileName, pattern, key = None):
# Load and index
with collection(featureFileName, "r") as featureFile:
featureIdx = index.Index()
features = []
for feature in featureFile:
try:
shape = asShape(feature['geometry'])
features.append(feature)
featureIdx.add(len(features) - 1, shape.bounds)
except ValueError:
print "Error parsing feature"
pprint(feature)
# Break up by sections and export
with collection(sectionFileName, "r") as sectionFile:
i = 0
for section in sectionFile:
fileName = pattern % i
if key:
fileName = pattern % section['properties'][key]
properties = {}
try:
with collection(fileName, 'w', 'ESRI Shapefile',
schema = featureFile.schema,
crs = featureFile.crs) as output:
sectionShape = asShape(section['geometry'])
for j in featureIdx.intersection(sectionShape.bounds):
if asShape(features[j]['geometry']).intersects(sectionShape):
properties = features[j]['properties']
output.write(features[j])
print "Exported %s" % fileName
i = i + 1
except ValueError:
print "Error exporting " + fileName
pprint(properties)
pprint(featureFile.schema)
示例4: test_create_extent
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def test_create_extent(self):
package = factories.Dataset()
geojson = json.loads(self.geojson_examples['point'])
shape = asShape(geojson)
package_extent = PackageExtent(package_id=package['id'],
the_geom=WKTElement(shape.wkt,
self.db_srid))
package_extent.save()
assert_equals(package_extent.package_id, package['id'])
if legacy_geoalchemy:
assert_equals(Session.scalar(package_extent.the_geom.x),
geojson['coordinates'][0])
assert_equals(Session.scalar(package_extent.the_geom.y),
geojson['coordinates'][1])
assert_equals(Session.scalar(package_extent.the_geom.srid),
self.db_srid)
else:
from sqlalchemy import func
assert_equals(
Session.query(func.ST_X(package_extent.the_geom)).first()[0],
geojson['coordinates'][0])
assert_equals(
Session.query(func.ST_Y(package_extent.the_geom)).first()[0],
geojson['coordinates'][1])
assert_equals(package_extent.the_geom.srid, self.db_srid)
示例5: _get_extent_object
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def _get_extent_object(self, geometry):
if isinstance(geometry, basestring):
geometry = json.loads(geometry)
shape = asShape(geometry)
return PackageExtent(package_id='xxx',
the_geom=WKTElement(shape.wkt, 4326))
示例6: asShape
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def asShape(self):
return asShape(self)
示例7: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
borough = ""
boros = {"1":"Manhattan", "2": "Bronx", "3":"Brooklyn", "4": "Queens", "5": "Staten Island"}
if properties.get("BORO"):
borough = boros[properties["BORO"]] + ", "
block = ""
if properties.get("BLOCK"):
block = "Block " + str(properties["BLOCK"]) +", "
name = borough + block + "Lot " + str(properties["LOT"])
bbl = properties.get("BBL") #stored with uris
#feature code mapping
feature_code = "ADM7"
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + bbl
uri_bbl = "bbl:"+bbl
timeframe = {}
updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"uris":[uri, uri_bbl],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
#print place
dump.write(uri, place)
示例8: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
if properties["NAME"]:
name = properties["NAME"]
else:
continue
#feature code mapping
feature_code = "ADM3"
if properties["LSAD"] == "Resvn":
feature_code = "RESV"
area = properties["CENSUSAREA"]
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + "." + properties["GEO_ID"] + "."+ feature["id"]
timeframe = {}
timeframe = {"start": "2000-01-01","start_range":0, "end": "2010-01-01", "end_range":0}
updated = "2012-01-31"
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"area": area,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
#print place
dump.write(uri, place)
示例9: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
if simplify_tolerance:
geom_obj = geom_obj.simplify(simplify_tolerance)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
geometry = mapping(geom_obj)
if properties["FULL_NAME"]:
name = properties["FULL_NAME"]
#feature code mapping
feature_code = "ADM1H"
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + "." + properties["ID"] + "."+ str(properties["VERSION"])
#1766/07/02 to 1766-01-01
timeframe = {"start": properties["START_DATE"].replace('/','-'), "start_range":0,
"end": properties["END_DATE"].replace('/','-'), "end_range":0}
#TODO admin? for counties?
updated = "2011-10-01"
area = properties["AREA_SQMI"]
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"updated": updated,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[],
"area": area
}
dump.write(uri, place)
示例10: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
if properties["NAME"]:
name = properties["NAME"]
else:
continue
#feature code mapping
feature_code = "ADM3"
if properties["LSAD_TRANS"] == "Reservation":
feature_code = "RESV"
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + "." + properties["COUSUBFP"] + "."+ feature["id"]
timeframe = {}
timeframe = {"start": "1990-01-01", "start_range":0, "end": "2000-01-01", "end_range":0}
updated = "2012-01-31"
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
#print place
dump.write(uri, place)
示例11: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
boros = {"1":"Manhattan", "2": "Bronx", "3":"Brooklyn", "4": "Queens", "5": "Staten Island"}
name = "Block "+str(properties["BLOCK"])
if properties.get("BORO"):
borough = boros[properties["BORO"]]
name = borough + ", Block "+ str(properties["BLOCK"])
#feature code mapping
feature_code = "ADM6"
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
bb = str(properties.get("BORO"))+str(properties["BLOCK"])
uri = uri_name + bb +"/"+feature["id"]
uri_bb = "bb:"+bb
timeframe = {}
updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"uris":[uri,uri_bb],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
#print place
dump.write(uri, place)
示例12: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
if simplify_tolerance:
geom_obj = geom_obj.simplify(simplify_tolerance)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
geometry = mapping(geom_obj)
if properties["FULL_NAME"]:
name = properties["FULL_NAME"]
#feature code mapping
feature_code = "ADM2H" #default code (building)
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + "." + properties["ID"] + "."+ str(properties["VERSION"])
#1766/07/02 to 1766-01-01
timeframe = {"start": properties["START_DATE"].replace('/','-'), "start_range":0,
"end": properties["END_DATE"].replace('/','-'), "end_range":0}
#TODO admin? for counties?
updated = "2010-02-12"
area = properties["AREA_SQMI"]
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"updated": updated,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[],
"area": area
}
dump.write(uri, place)
示例13: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
name = properties.get("NAME")
#feature code mapping
feature_code = "HSTS"
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + properties["LP_Number"]
timeframe = {}
updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
dump.write(uri, place)
示例14: extract_shapefile
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
for feature in collection(shapefile, "r"):
geometry = feature["geometry"]
properties = feature["properties"]
#calculate centroid
geom_obj = asShape(geometry)
try:
centroid = [geom_obj.centroid.x , geom_obj.centroid.y]
except AttributeError:
print "Error: ", feature
continue
if properties["NAME"]:
name = properties["NAME"]
else:
continue
#feature code mapping
feature_code = "ADM3"
area = properties["AREATOT"]
source = properties #keep all fields anyhow
# unique URI which internally gets converted to the place id
# Must be unique!
uri = uri_name + "." + properties["GEOID"] + "."+ feature["id"]
timeframe = {}
timeframe = {"start": "1980-01-01", "start_range": 0, "end": "1990-01-01", "end_range":0}
updated = "2012-01-31"
place = {
"name":name,
"centroid":centroid,
"feature_code": feature_code,
"geometry":geometry,
"is_primary": True,
"source": source,
"alternate": [],
"updated": updated,
"area": area,
"uris":[uri],
"relationships": [],
"timeframe":timeframe,
"admin":[]
}
#print place
dump.write(uri, place)
示例15: test_update_extent
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import asShape [as 别名]
def test_update_extent(self):
package = factories.Dataset()
geojson = json.loads(self.geojson_examples['point'])
shape = asShape(geojson)
package_extent = PackageExtent(package_id=package['id'],
the_geom=WKTElement(shape.wkt,
self.db_srid))
package_extent.save()
if legacy_geoalchemy:
assert_equals(
Session.scalar(package_extent.the_geom.geometry_type),
'ST_Point')
else:
from sqlalchemy import func
assert_equals(
Session.query(
func.ST_GeometryType(package_extent.the_geom)).first()[0],
'ST_Point')
# Update the geometry (Point -> Polygon)
geojson = json.loads(self.geojson_examples['polygon'])
shape = asShape(geojson)
package_extent.the_geom = WKTElement(shape.wkt, self.db_srid)
package_extent.save()
assert_equals(package_extent.package_id, package['id'])
if legacy_geoalchemy:
assert_equals(
Session.scalar(package_extent.the_geom.geometry_type),
'ST_Polygon')
assert_equals(
Session.scalar(package_extent.the_geom.srid),
self.db_srid)
else:
assert_equals(
Session.query(
func.ST_GeometryType(package_extent.the_geom)).first()[0],
'ST_Polygon')
assert_equals(package_extent.the_geom.srid, self.db_srid)