python量表geojson按绝对值以米为单位
我正在尝试生成一个Python代码,该代码将包含多边形的Geojson作为输入,然后输出一个多边形,该多边形按精确值以米为单位缩放。例如,假设我的多边形是代表房屋的正方形,我想获得另一个正好20m大的正方形的输出。正方形这将很简单,但是相当困难的形状很难。
这是我现在使用的(在这里找到 scale geojson和附近的经度点):
import json
from shapely import affinity
from shapely.geometry import shape, Point, mapping
def handler(event, context):
with open('polygon.geojson', encoding='utf-8') as f:
js = json.load(f)
polygon = shape(js['features'][0]['geometry'])
polygon_nearby = affinity.scale(polygon, xfact=1.1, yfact=1.1)
print(json.dumps({"type": "FeatureCollection", "features": [{"type": "Feature", 'properties': {}, 'geometry': mapping(polygon)}]}))
print(json.dumps({"type": "FeatureCollection", "features": [{"type": "Feature", 'properties': {}, 'geometry': mapping(polygon_nearby)}]}))
if __name__ == '__main__':
handler(None, None)
但是,正如您可以通过实地值(10%)看到此量表,我想将其更改为以米为单位的绝对值。
谢谢您的任何建议
I am trying to generate a python code that takes geojson containing polygon as input an then outputs a polygon that is scaled by exact value in meters. For example lets say that my polygon is a square representing a house and I want to get an output of another square that is exactly 20m bigger on each side. This would be simple with square but it is quite hard with complex shapes.
Heres is what I use now (found here Scale GeoJSON to find latitude and longitude points nearby):
import json
from shapely import affinity
from shapely.geometry import shape, Point, mapping
def handler(event, context):
with open('polygon.geojson', encoding='utf-8') as f:
js = json.load(f)
polygon = shape(js['features'][0]['geometry'])
polygon_nearby = affinity.scale(polygon, xfact=1.1, yfact=1.1)
print(json.dumps({"type": "FeatureCollection", "features": [{"type": "Feature", 'properties': {}, 'geometry': mapping(polygon)}]}))
print(json.dumps({"type": "FeatureCollection", "features": [{"type": "Feature", 'properties': {}, 'geometry': mapping(polygon_nearby)}]}))
if __name__ == '__main__':
handler(None, None)
However as you can see this scales by realtive value (10%) and I would like to change that to absolute value in meters.
Thank you in forward for any suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论