开发者

Using OpenMap API which class do I use to extract point data from the shapefile?

I am currently using Shapefile class and ColdFusion to go through the "records" of each shapefile. Each record has a bounding box and i am able to get this information but havent found a way to actually retrieve the points inside each record.

Can someone shed some light on which classes to use and how to use them?

This is the exact same situation(including some verbage) as:

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

Allthough I am using ColdFusion, I do believe that any hints to the solution would help me greatly.

My current test code is as follows:

<cfset shapeFile = createObject("ja开发者_开发知识库va","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()#"> 


I've never used this, or done any GIS, but after looking at the API, here's my suggestion.

So, after you have your shapefile, you would:

myESRIRecord = shapeFile.getNextRecord();

This gets you an ESRIRecord class or one of its subclasses, depending on what type of shape it is.

The shapefile I've messed with to figure this out is:

http://russnelson.com/india.zip

And only contains polygon types.

The ESRIPolygonRecord contains a property called "polygons" which contains an array of com.bbn.openmap.layer.shape.ESRIPoly$ESRIFloatPoly instances.

The key with this library, it seems, is that a lot of the data is in properties, not accessible through methods.

So, as I said, the ESRIPolygonRecords has its data in the polygons property, the ESRIPointRecord has its data in the x and y properties. So, if you were looking for a getX() or getY(), thats why you didn't find it.

This sample code worked for me:

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜