简体   繁体   English

缩放 GeoJSON 以查找附近的纬度和经度点

[英]Scale GeoJSON to find latitude and longitude points nearby

I am trying to scale GeoJSON polygons using shapely (any other method will do as long as I can run it on an AWS Lambda function).我正在尝试使用 shapely 缩放 GeoJSON 多边形(只要我可以在 AWS Lambda 函数上运行它,任何其他方法都可以)。 My goal is to find latitude and longitude points near the area described in the GeoJSON.我的目标是在 GeoJSON 中描述的区域附近找到经纬度点。 The GeoJSON files vary an example is: GeoJSON 文件变化的一个例子是:

{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[-1.4502, 51.2757], [-1.7798, 51.3443], [-3.7793, 50.9446], [-5.2515, 50.8059], [-5.4053, 50.6947], [-5.6689, 50.3455], [-5.6689, 50.3034], [-5.5371, 50.2332], [-4.5923, 50.2191], [-3.7134, 50.3455], [-3.4058, 50.4855], [-2.3511, 50.8059], [-1.7139, 50.8198], [-1.626, 50.8476], [-1.4502, 51.0276], [-1.4502, 51.2757]]]]}}]}

The code I currently have is:我目前拥有的代码是:

import json
from shapely import affinity
from shapely.geometry import shape, Point, mapping

def handler(event, context):
    with open('polygon.json') 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)}]}))
    for point in [(-1.7798, 51.3442), (-1.7798, 51.3444), (-1.4504, 51.27), (-1.4503, 51.28)]:
        if polygon.contains(Point(point)):
            print('Found point in polygon', point)
        elif polygon_nearby.contains(Point(point)):
            print('Found point nearby', point)
        else:
            print("Not found", point)

if __name__ == '__main__':
    handler(None, None)

The problem is that when the polygon scales it currently scales from a central point.问题是当多边形缩放时,它当前是从中心点缩放的。 Boundaries above the central point are not scaled, as shown in the following image:中心点上方的边界未缩放,如下图所示: 渲染 GeoJSON 以显示缩放问题

The image above is a representation of the original GeoJSON (dark grey) and the nearby GeoJSON (light grey).上图是原始 GeoJSON(深灰色)和附近 GeoJSON(浅灰色)的表示。 The boundary above Poole (on the map) is the same for both.普尔上方的边界(在地图上)对两者来说是相同的。 This I think is because the boundary is above the central point which it was scaled from.我认为这是因为边界高于它被缩放的中心点。

What I am trying to achieve is for the polygon_nearby to be scaled so that all the boundaries are bigger than in the original polygon or any other method of finding latitude and longitude points near the area described in the original GeoJSON.我想要实现的是对polygon_nearby进行缩放,以使所有边界都大于原始polygon或任何其他在原始 GeoJSON 中描述的区域附近查找纬度和经度点的方法。

I figured it out use:我想通了使用:

polygon_nearby = polygon.buffer(0.1)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在距海岸线固定距离处找到点(纬度,经度)? - How to find points(latitude, longitude) at a fixed distance from the coast line? 将几何点从 GeoJSON 转换为纬度和经度 - Converting a geometry point from GeoJSON to latitude and longitude python中最近的经纬度点 - Nearest latitude and longitude points in python 找到最近的纬度和经度 - Find the closest latitude and longitude 如何在不做循环的情况下找到给定经度和纬度的两点之间的距离? - How to find the distance between two points given longitude and latitude without do loop? 如何在python-error中找到在给定经度和纬度的两点之间的距离? - How to find the distance between two points given longitude and latitude in python-error? 如何在 Python Pandas 中找到 5 英里半径内给定纬度和经度的点列表的密度? - How do I find the density of a list of points given latitude and longitude in a 5 mile radius in Python Pandas? 在 GeoPandas 中将纬度/经度点转换为网格多边形 - Convert Latitude/Longitude points to Grid Polygons in GeoPandas 基于纬度/经度的点列表之间的距离 - Distance between list of points based on latitude/longitude 具有纬度和经度的点集合之间的成对距离 - Pairwise distance between collections of points with latitude and longitude
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM