是否有 python 代码来解析 geoPDF 文件以获取投影和图像数据? geoPDF2KML 工具?

发布于 2024-09-26 17:18:04 字数 188 浏览 0 评论 0原文

我想组织大量的 geoPDF 文件,以便可以轻松地在 Google 地图和 Google 地球上叠加查看它们。

我认为,我的第一步是将 geoPDF 转换为 jpg 类型图像,然后需要匹配的纬度、经度信息。

是否有 python 代码来解析 geoPDF 文件以获取投影和图像数据?

geoPDF2KML 工具?

I want to organize lots of geoPDF files so they can easily viewed overlayed onto Google Maps and Google Earth.

My 1st step, I think, is to convert the geoPDF to a jpg type image which then needs matching lat,long information.

Is there python code to parse a geoPDF file to get the projection and image data?

A geoPDF2KML tool?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

说好的呢 2024-10-03 17:18:04

我在具有 python 的 ubuntu 系统上使用的步骤(python 已经是 Unbuntu 的一部分)
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 

Steps I used on ubuntu system that has python (python already part of Unbuntu)
1. download and install poppler
2. download and install proj4
3. download and install 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 
半岛未凉 2024-10-03 17:18:04

一种选择是使用 GDAL...

gdal 的最新版本(即当前的 svn trunk,而不是任何发布的版本)应该支持 geoPDF。

您需要使用选项 --with-poppler=yes 进行编译,并安装 poppler pdf 库。 (编译 gdal 可能有点痛苦,只是为了提前警告你......)

Gdal 的 python 绑定很痛苦,但它们通常可以工作。

从那里,您应该能够轻松地使用 GDAL 将您的 geopdf 转换为地理参考 jpeg。

不过,如果您还不熟悉 GDAL,这可能会带来麻烦而不值得。 geoPDF 中的地理配准信息可能可以通过其他方式提取...

希望这能有所帮助...

One option is to use GDAL...

The latest version (i.e. the current svn trunk, not any released version) of gdal should support geoPDF's.

You'll need to compile it with the option --with-poppler=yes and have the poppler pdf library installed. (Compiling gdal can be a bit of a pain, just to warn you ahead of time...)

Gdal's python bindings are painful, but they generally work.

From there, you should be able to easily use GDAL to convert your geopdf's to georeferenced jpegs.

If you're not already familiar with GDAL, though, this may be more trouble than it's worth. The georeferenceing information in a geoPDF can probably be extracted in other ways...

Hope that helps a bit, anyway...

爱已欠费 2024-10-03 17:18:04

下面的代码可能有助于指导那些想要将许多 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

This code below may help guide some one wanting to convert many geoPDFs to KML-Superoverlay which can then be incorporated as web map overlays using Google Maps API or 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
千鲤 2024-10-03 17:18:04

Python 库 pdfrw (https://pypi.org/project/pdfrw/) 将返回坐标参考信息。下面的示例将从 ArcGIS Pro (3.x) 中制作的地理参考 PDF 中提取坐标系 - 其他来源可能有所不同。结合这三个方面应该允许您在其他地方(例如 KML)对 PDF 的内容进行地理配准。

from pdfrw import PdfReader
myPDF = r'path\to\my.pdf'
x = PdfReader(myPDF)
myGeoCoords = x.pages[0]['/VP'][0]['/Measure']['/GPTS'] #lat/long extent of georeference
myPageCoords = x.pages[0]['/VP'][0]['/Measure']['/LPTS'] #extent on the page of the georeference
myCoordSystem = x.pages[0]['/VP'][0]['/Measure']['/GCS'] #projection information in WKT format

The Python library pdfrw (https://pypi.org/project/pdfrw/) will return the coordinate reference information. The below example will pull the coordinate system from a georeferenced PDF made in ArcGIS Pro (3.x) -- other sources may differ. Combing these three aspects should allow you to georeference the contents of the PDF elsewhere (e.g. KML).

from pdfrw import PdfReader
myPDF = r'path\to\my.pdf'
x = PdfReader(myPDF)
myGeoCoords = x.pages[0]['/VP'][0]['/Measure']['/GPTS'] #lat/long extent of georeference
myPageCoords = x.pages[0]['/VP'][0]['/Measure']['/LPTS'] #extent on the page of the georeference
myCoordSystem = x.pages[0]['/VP'][0]['/Measure']['/GCS'] #projection information in WKT format
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文