6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pyprojで測地系変換を高速に行う

Last updated at Posted at 2019-07-11

変換元と変換先の測地系が決まっている場合、大量の座標を変換するのに時間がかかっていたので、調べたら良さそうな方法があったので記載

csvなどで付加情報もある場合はtransformerクラスを使うとよい
https://pyproj4.github.io/pyproj/latest/optimize_transformations.html

proj_trans.py
import pyproj
from pyproj import Transformer

class GeoTrans(object):
	def __init__(self, from_epsg=4301,to_epsg=4326):
		"""コンストラクタ
		
		Keyword Arguments:
			from_epsg {int} -- [変換元のEPSGコード] (default: {4301})
			to_epsg {int} -- [変換先のEPSGコード] (default: {4326})
		"""
		self.from_epsg = pyproj.Proj('+init=EPSG:{}'.format(from_epsg))
		self.to_epsg = pyproj.Proj('+init=EPSG:{}'.format(to_epsg))
		self._transformer = Transformer.from_proj(self.from_epsg,self.to_epsg)

	def transform(self,lon:float,lat:float): 
		"""測地系変換
		
		Arguments:
			lon {float} -- [経度]
			lat {float} -- [緯度]
			
		Returns:
			[taple] -- [経度,緯度]
		"""
		return self._transformer.transform(lon,lat)
			

if __name__ == "__main__" :
	tky2wgs = GeoTrans(4301,4326)
	wgs2tky = GeoTrans(4326,4301)
	
	lonlats = [(139.742631,35.723784)]
	
	for ll in lonlats:
		# 日本測地→世界測地(WGS84)
		wgs = tky2wgs.transform(ll[0],ll[1])
		print('wgs84:{0[0]:f},{0[1]:f}'.format(wgs))
		# 世界測地(WGS84)→日本測地
		tky = wgs2tky.transform(wgs[0],wgs[1])
		print('tky97:{0[0]:f},{0[1]:f}'.format(tky))
	

座標列を変換する場合はproj.itransformを使うでもよい。

昔pyprojをつかった時はtransformerクラスとかあったかな?と思ったら
今年の3月に追加されてた・・・

6
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?