2017-09-06 15 views
0

10km x 10kmの中心点から始まる境界ボックスを作成するにはどうすればよいですか?GeoDjango:10km x 10kmの中心点から境界ボックスを作成する方法

今、私は以下のようにしています。しかし、これは良いと正確な解決策ではありません。

lng30km = 0.42 # I measured this values with google maps 
lat30km = 0.27 # It is not accurate and won't work properly 
minx = point.x - lng30km 
miny = point.y - lat30km 
maxx = point.x + lng30km 
maxy = point.y + lat30km 
poly = Polygon.from_bbox((minx, miny, maxx, maxy)) 

は、私は(これだけを試してみてください

ne_lat、あなたがsw_lng、sw_lat、ne_lngを計算したら、このバウンディングボックス

MyObject.objects.filter(point__within=poly 

答えて

0

以内に私のMySQL DB内のポイントを見つけるために、このバウンディングボックスを使用したいですpostgresでテスト)私はMySqlについてはあまりよく分かりません。とにかくPostGISを使うべきです。 MySqlには多くの制限があります。例えば

xmin = float(sw_lng) 
    ymin = float(sw_lat) 
    xmax = float(ne_lng) 
    ymax = float(ne_lat) 
    bbox = (xmin, ymin, xmax, ymax) 
    geom = Polygon.from_bbox(bbox) 

    values = use_class.objects.filter(active=True, source__coveredby=geom) 

(擬似コードテストされていない):

geod = pyproj.Geod(ellps='WGS84') 

dis = 30000/2 

top_x, top_y, top_azi = geod.fwd(center_longitude, center_latitude, 0, dis) 
right_x, right_y, right_azi = geod.fwd(center_longitude, center_latitude, 90, dis) 
bottom_x, bottom_y, bottom_azi = geod.fwd(center_longitude, center_latitude, 180, dis) 
left_x, left_y, left_azi = geod.fwd(center_longitude, center_latitude, 270, dis) 

これは距離によって中央0、90、180、270を移動させることにより、クロス産卵3万メートルを構築します。

+0

**あなたがsw_lng、sw_lat、ne_lng、ne_lat ** を計算したら、これが私の質問です。それを計算する方法? –

+0

私は共有のために0,90,180,270 – mbieren

0

与えられた経度 - 緯度のバウンディングボックスを正確に計算するには、測地線計算を行う必要があります。これはpyprojライブラリで実現できます。 pyprojの詳細なドキュメントはhereです。

端末にpipをインストールします。あなたの緯度と経度、バウンディングボックスが与えられる

pip install pyproj 

は、北東、南東、南西、および北西の角です。これらのそれぞれは、対応する45°、135°、225°および315°の方位角値を持ちます。

from pyproj import Geod 

g = Geod('clrk66') # Create a geodesic calculation object 
distance = 10 * 1000 # in meters 

# given latitude (lat), longitude (lon) values for the location 
top_right_corner = g.fwd(lon, lat, 45, distance) 
bottom_right_corner = g.fwd(lon, lat, 135, distance) 
bottom_left_corner = g.fwd(lon, lat, 225, distance) 
top_left_corner = g.fwd(lon, lat, 315, distance) 

ボックスの境界はこれらのコーナーから入手できます。今すぐpyproj値を使用して、あなたはこのような何かを行うことができます。

max_lon = top_right_corner[0] 
max_lat = bottom_right_corner[1] 
min_lon = bottom_left_corner[0] 
min_lat = top_left_corner[1] 

これを使用して、境界ボックスのポリゴンを作成できます。

bbox = (max_lon, max_lat, min_lon, min_lat) 
geom = Polygon.from_bbox(bbox) 
+0

の角度を使って 'pyproj.Geod.fwd'メソッドと距離オブジェクト' D(km = 30) 'を使うことで実現できます。なぜあなたはclrk66楕円体を選んだのですか?私のロングとラットはGoogleマップからです。だから私は正しいWGS84を使わなければならないのですか? –

関連する問題