OpenMap API を使用して、シェープファイルからポイント データを抽出するにはどのクラスを使用すればよいですか?
-
03-10-2019 - |
質問
現在、Shapefile クラスと ColdFusion を使用して、各シェープファイルの「レコード」を調べています。各レコードには境界ボックスがあり、この情報を取得することはできますが、各レコード内のポイントを実際に取得する方法は見つかりませんでした。
誰かがどのクラスを使用するか、そしてそれらの使用方法を明らかにしてもらえますか?
これは次とまったく同じ状況です (一部の表現を含む)。
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()#">
解決
私はこれを使用したことも、GIS を行ったこともありませんが、API を見た後、私の提案は次のとおりです。
したがって、シェープファイルを取得したら、次のようにします。
myESRIRecord = shapeFile.getNextRecord();
これにより、 ESRI記録 形状のタイプに応じて、クラスまたはそのサブクラスの 1 つ。
これを理解するために私がいじったシェープファイルは次のとおりです。
http://russnelson.com/india.zip
そして含まれるのは ポリゴン 種類。
ESRIPolygonRecord には、com.bbn.openmap.layer.shape.ESRIPoly$ESRIFloatPoly インスタンスの配列を含む「polygons」と呼ばれるプロパティが含まれています。
このライブラリの重要な点は、多くのデータがプロパティ内にあり、メソッドからはアクセスできないことのようです。
したがって、前述したように、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>