2010-09-17 46 views
1

我目前使用Shapefile類和ColdFusion來通過每個shapefile的「記錄」。每個記錄都有一個邊界框,我能夠獲得這些信息,但沒有找到一種方法實際檢索每個記錄內的點。使用OpenMap API哪些類用於從shapefile中提取點數據?

有人可以瞭解哪些課程使用以及如何使用它們?

這是完全相同的情況(包括一些verbage)爲:

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

Allthough我使用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()#"> 
+1

也許你可以從他們那裏直接獲得支持? http://openmap.bbn.com/contacts.html – Henry 2010-09-17 19:35:37

回答

2

我從來沒有用過這個,或者做任何GIS,但看着API後,這裏是我的建議。

所以,以後你有你的Shape文件,您可以:

myESRIRecord = shapeFile.getNextRecord(); 

這可以讓你的ESRIRecord類或它的一個子類,這取決於它是什麼類型的形狀。

我已經搞砸算出這個shape文件是:

http://russnelson.com/india.zip

,只包含polygon類型。

ESRIPolygonRecord包含一個名爲「polygons」的屬性,其中包含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> 
+0

這工作得很好,我不得不改變一些周圍的事情與藍色的cfloop不支持數組屬性,但效果很好。太感謝了! – cfEngineers 2010-09-17 22:52:17

+0

我很高興它爲你工作!這個問題讓我感興趣的是更多地使用這個庫! – 2010-09-18 01:03:45

相關問題