首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用shapefile API我应该使用哪个类从OpenMap中提取点数据?

使用shapefile API我应该使用哪个类从OpenMap中提取点数据?
EN

Stack Overflow用户
提问于 2010-09-18 02:15:22
回答 1查看 1.4K关注 0票数 1

我目前正在使用shapefile类和ColdFusion来浏览每个Shapefile的“记录”。每条记录都有一个边界框,我能够获得这些信息,但还没有找到一种方法来实际检索每条记录中的点。

有人能解释一下应该使用哪些类以及如何使用它们吗?

这与以下情况完全相同(包括一些动词):

http://old.nabble.com/what-class-do-you-use-to-extract-data-from-.SHP-files--td20208204.html

虽然我使用的是ColdFusion,但我相信任何有关解决方案的提示都会对我有很大的帮助。

我当前的测试代码如下:

代码语言:javascript
复制
<cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile")>

<cfset shapeFile.init('/www/_Dev/tl_2009_25_place.shp')>

<cfoutput>
 getFileLength = #shapeFile.getFileLength()#<br>
 getFileVersion = #shapeFile.getFileVersion()#<br>
 getShapeType = #shapeFile.getShapeType()#<br>
 toString = #shapeFile.toString()#<br>
</cfoutput>
<cfdump var="#shapeFile#"> 
<cfdump var="#shapeFile.getBoundingBox()#"> <br>
<cfdump var="#shapeFile.getNextRecord()#"> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-18 06:27:29

我从来没有使用过这个,也没有做过任何GIS,但在看过API之后,这里是我的建议。

因此,在拥有shapefile之后,您将:

代码语言:javascript
复制
myESRIRecord = shapeFile.getNextRecord();

这会得到一个ESRIRecord类或它的一个子类,具体取决于它的形状类型。

我处理过的shapefile是这样的:

http://russnelson.com/india.zip

并且只包含polygon类型。

多边形包含一个名为“ESRIPolygonRecord”的属性,该属性包含一个com.bbn.openmap.layer.shape.ESRIPoly$ESRIFloatPoly实例数组。

这个库的关键之处在于,许多数据都在属性中,无法通过方法访问。

因此,正如我所说的,ESRIPolygonRecords的数据在polygons属性中,ESRIPointRecord的数据在x和y属性中。因此,如果您正在寻找getX()或getY(),这就是您找不到它的原因。

以下示例代码适用于我:

代码语言:javascript
复制
<cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile")>

<cfset shapeFile.init('/tmp/india-12-05.shp')>

<!--- There may be more then one record, so you can repeat this, or loop to get
      more records --->
<cfset myRecord = shapeFile.getNextRecord()>

<!--- Get the polygons that make up this record --->
<cfset foo = myRecord.polygons>

<cfdump var="#foo#">

<cfloop array="#foo#" index="thispoly">
<cfoutput>
    This poly has #thisPoly.nPoints# points:<br>
    <!--- because java arrays are 0 based --->
    <cfset loopEnd = thisPoly.nPoints-1>
    <cfloop from="0" to="#loopEnd#" index="i">
        X: #thisPoly.getX(i)#   Y: #thisPoly.getY(i)#<br>
    </cfloop>
    <!--- Returns points as array --->
    <cfdump var="#thisPoly.getDecimalDegrees()#">
    <cfdump var="#thisPoly.getRadians()#">
</cfoutput>
</cfloop>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3737861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档