python量表geojson按绝对值以米为单位

发布于 2025-02-10 20:29:00 字数 1090 浏览 1 评论 0原文

我正在尝试生成一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文