www.TimeGIS.com

时空地图 www.TimeGIS.com

交互式图形化建模仿真软件开发

导航

一种简单的的方法 Esri arcgis shape (*.shp) 文件转换 google earth kml 格式

谷歌地球里面可以显示KML工具,但是很多地图都是Shp文件格式,所以需要转换一下。

Esri 的地图文件 shp 格式转google earth kml的方法很多,有人说利用Arcgis来转,但是如果没有arcgis, 是不是有另外方法?

可以利用免费的Ogr2Ogr.exe命令行工具进行转换,它们都是开源的工具,GDAL/OGR Binaries Proj.4 FWTools 你可以从下面的连接下载

http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries

http://trac.osgeo.org/proj/       这里下载 proj.dll

当然,最好是一口气从这里下载 http://fwtools.maptools.org/

 

上帝之眼 http://www.godeyes.cn/ 里面有人已经提到使用Ogr2Ogr把Shp文件转换为KML文件的方法:
1.下载并安装 FWTools,
2.下载并安装 Google Earth.
3从“开始”中选择 "FWTools Shell"
4.下载压缩文件 zipped shape file. (shp文件里面有prj投影文件)
5.解压缩文件到 C:\temp\
6.在控制平台中输入如下命令,回车即可完成转换
ogr2ogr.exe -f KML C:\temp\smdo2.kml C:\temp\smdo2

 

当然,英文版的说得更明白,摘录如下: http://code.google.com/intl/zh-CN/apis/kml/articles/vector.html

ogr2ogr

GDAL provides a powerful set of libraries for working with vector data. In particular, ogr2ogr is a powerful utility for data conversion. Many applications, including some of those mentioned above, incorporate GDAL/OGR.

To get started, download and install GDAL. Then you will need a shapefile. For purposes of this tutorial, try using one from DataSF. The example below uses the realtor_neighborhoods shapefile, which can be obtained, after agreeing to their license, here. Once you've downloaded the file, unzip it into a directory that you will remember. Open up a command line and navigate to the directory that you put the data in. Now for the fun part.

ogr2ogr can be used from the command line very easily. Here is how you could convert realtor_neighborhoods from a shapefile to KML:

ogr2ogr -f "KML" -where "NBRHOOD='Telegraph Hill'" realtor_neighborhoods.kml realtor_neighborhoods.shp

Here's a breakdown of what that command does:

  • ogr2ogr: This is the core command.
  • -f "KML: This sets the output format to KML.
  • -where "NBRHOOD='Telegraph Hill'": This is an optional where clause, like in SQL. Basically, it allows you to query the data based on metadata. It works with shapefiles and other file types that support querying. In this case, it is querying for the NBRHOOD field, and only selecting features that have a NBRHOOD of Telegraph Hill. If you leave that parameter off, ogr2ogr gives you every neighborhood polygon.
  • realtor_neighborhoods.kml: This is the output file name. Output file name comes first.
  • realtor_neighborhoods.shp: This is the input file name. The .shp file represents the whole shapefile.

That's it, it's very simple. This command writes a KML file that looks like this:

<?xml version="1.0" encoding="utf-8" ?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
 
<Document><Folder><name>realtor_neighborhoods</name> 
   
<Schema name="realtor_neighborhoods" id="realtor_neighborhoods"> 
     
<SimpleField name="Name" type="string"></SimpleField> 
     
<SimpleField name="Description" type="string"></SimpleField> 
     
<SimpleField name="OBJECTID" type="float"></SimpleField> 
     
<SimpleField name="NBRHOOD" type="string"></SimpleField> 
     
<SimpleField name="SFAR_DISTR" type="string"></SimpleField> 
   
</Schema> 
   
<Placemark> 
     
<ExtendedData><SchemaData schemaUrl="#realtor_neighborhoods"> 
       
<SimpleData name="OBJECTID">81</SimpleData> 
       
<SimpleData name="NBRHOOD">Telegraph Hill</SimpleData> 
       
<SimpleData name="SFAR_DISTR">District 8 - Northeast</SimpleData> 
     
</SchemaData></ExtendedData> 
     
<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.41041847319012,37.805924016582715,0 -122.407203813674,37.806324902060979,0 -122.40667792852096,37.803710121958744,0 -122.40348255423899,37.804117462290641,0 -122.40237202127015,37.798540648764529,0 -122.40876046662795,37.797723222540775,0 -122.41041847319012,37.805924016582715,0</coordinates></LinearRing></outerBoundaryIs></Polygon> 
     
<Style><LineStyle><color>ff0000ff</color></LineStyle>  <PolyStyle><fill>0</fill></PolyStyle></Style> 
   
</Placemark> 
 
</Folder></Document></kml>

本人实际操作了一下,可行,放上截图,转换好后的kml显示中文也许有乱码问题,

这时可以用notepad打开kml文件,然后用utf-8方式再存一下盘,就可以了。

 

 

posted on 2011-12-05 20:36  时空地图-TimeGIS-com  阅读(1944)  评论(0编辑  收藏  举报

www.TimeGIS.com