有没有Python代码可以解析geoPDF文件以获取投影和图像数据?有没有geoPDF2KML工具?
我想把很多geoPDF文件整理一下,这样就可以方便地在谷歌地图和谷歌地球上叠加查看。
我觉得第一步是把geoPDF文件转换成jpg格式的图片,然后还需要配上对应的经纬度信息。
有没有Python代码可以解析geoPDF文件,以获取投影和图像数据呢?
有没有geoPDF转KML的工具?
3 个回答
2
下面的代码可能会帮助那些想把很多geoPDF文件转换成KML-Superoverlay的人,这样就可以通过Google Maps API或者Google Earth API把它们作为网页地图的覆盖层使用...
import shlex
import subprocess
from subprocess import Popen, PIPE
import os
def step1_translate( input_file ):
out = input_file + ".vrt"
translate_command = "gdal_translate -of VRT %s %s" % (input_file,out)
translate_args = shlex.split( translate_command )
p1 = subprocess.Popen( translate_args) # translate
print p1
def step2_warp( input_file):
gdalwarp_command = "gdalwarp -of VRT -t_srs EPSG:4326 %s %s" % (output_file,output_file2)
gdalwarp_args = shlex.split( gdalwarp_command )
p2 = subprocess.Popen( gdalwarp_args , stdin=p1.stdout ) #gdalwarp
def step3_tile( input_file, output_file, output_file2 ):
gdal2tiles_command = "/home/boris/gdal/swig/python/scripts/gdal2tiles.py -p geodetic -k %s" % output_file2
gdal2tiles_args = shlex.split( gdal2tiles_command )
p3 = subprocess.Popen( gdal2tiles_args , stdin=p2.stdout) #gdal2tiles
3
我在一个已经装了Python的Ubuntu系统上使用的步骤(Python是Ubuntu的一部分):
1. 下载并安装poppler
2. 下载并安装proj4
3. 下载并安装gdal
poppler$./configure --enable-xpdf-headers --prefix=/usr/local/include/poppler" then the usual "$make" and "$make install"
poppler$make
poppler$sudo make install
sudo apt-get install proj4
gdal$./configure --with-static-proj4=/usr/local/lib --with-threads --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-gif=internal --with-png=internal --with-libz=internal --with-poppler=/usr/local/include/poppler --with-python
gdal$make
gdal$sudo make install
2
一个选择是使用GDAL...
最新版本的gdal(也就是当前的svn主干版本,而不是任何已发布的版本)应该支持geoPDF格式。
你需要在编译时加上选项--with-poppler=yes
,并且要安装poppler这个PDF库。(编译gdal可能会有点麻烦,提前提醒你一下…)
GDAL的Python接口使用起来有点痛苦,但一般来说还是能用的。
这样一来,你就可以轻松地使用GDAL将你的geoPDF转换为地理参考的JPEG图片。
不过,如果你对GDAL还不熟悉,这可能会比你想象的要麻烦。geoPDF中的地理参考信息可能还有其他方法可以提取…
希望这些信息能对你有所帮助…