views:

81

answers:

1

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("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()#"> 
+1  A: 

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>
Edward M Smith
This worked great, I had to change some things around for BlueDragon with the cfloop not supporting the array attribute, but works well. Thanks a million!
cfEngineers
I'm pleased it worked out for you! This question has me interested in messing around more with this library!
Edward M Smith