我目前正在使用shapefile类和ColdFusion来浏览每个Shapefile的“记录”。每条记录都有一个边界框,我能够获得这些信息,但还没有找到一种方法来实际检索每条记录中的点。
有人能解释一下应该使用哪些类以及如何使用它们吗?
这与以下情况完全相同(包括一些动词):
http://old.nabble.com/what-class-do-you-use-to-extract-data-from-.SHP-files--td20208204.html
虽然我使用的是ColdFusion,但我相信任何有关解决方案的提示都会对我有很大的帮助。
我当前的测试代码如下:
<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()#"> 发布于 2010-09-18 06:27:29
我从来没有使用过这个,也没有做过任何GIS,但在看过API之后,这里是我的建议。
因此,在拥有shapefile之后,您将:
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(),这就是您找不到它的原因。
以下示例代码适用于我:
<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>https://stackoverflow.com/questions/3737861
复制相似问题