我們先從開始基礎的內部類開始學習,今天要講解的是拓撲的基礎要素“ 點 Point ”
點是一個0維的空間數據,一定包含XY坐標信息,可能包含Z、M屬性,上圖是OGC對於點的結構定義。
其中Z為三維高程數據,M(measure )與應用環境有關。(The m coordinate value allows the application environment to associate some measure with the point values. )
點要素在 geometry api java 中分為“點 Point ”和“頂點 Vertex”
Point 一般指點要素,包含X、Y、Z、M (double) 屬性
Vertex一般指構造中的點要素(組成線面體的基礎要素)
其中Vertex在Point 的基礎上還要添加所屬ID、內插屬性、貼圖坐標等特殊屬性與方法 (本文主要描述Point ,之后會在本文補償或者再寫一篇)
Point 的初始定義:
1.直接定義
1 public Point createPoint() { 2 3 Point pt = new Point(0.05, 0.05); 4 5 return pt; 6 }
2.讀取JSON數據
OperatorImportFromJson.local().executeexecute(Geometry.Type type, String string);
Type :Geometry.Type尋找,這里是Point
string :JSON字符串
1 public Point createPointFromJson() throws JsonParseException, IOException { 2 3 String jsonString = "{\"x\":-106.4453583,\"y\":39.11775,\"spatialReference\":{\"wkid\":4326}}"; 4 5 MapGeometry mapGeom = OperatorImportFromJson.local().execute(Geometry.Type.Point, jsonString); 6 return (Point)mapGeom.getGeometry(); 7 }
3.讀取GeoJSON數據
OperatorImportFromGeoJson.local().execute(int importFlags, Geometry.Type type, String geoJsonString, ProgressTracker progressTracker);
importFlags :
geoJsonImportDefaults = 0; 默認WGS84坐標系
geoJsonImportNonTrusted = 2; 不可信點
geoJsonImportSkipCRS = 8; 跳過CRS
geoJsonImportNoWGS84Default = 16; 非WGS84坐標系
type :Geometry.Type尋找,這里是Point
geoJsonString :GeoJSON字符串
progressTracker :null
1 public Point createPointFromGeoJson() throws JsonParseException, IOException { 2 3 String geoJsonString = "{\"type\":\"Point\",\"coordinates\":[-106.4453583,39.11775],\"crs\":\"EPSG:4326\"}"; 4 5 MapGeometry mapGeom = OperatorImportFromGeoJson.local().execute(GeoJsonImportFlags.geoJsonImportDefaults, Geometry.Type.Point, geoJsonString, null); 6 return (Point)mapGeom.getGeometry(); 7 }
4.讀取WKT數據
OperatorImportFromWkt.local().execute(int import_flags, Geometry.Type type,String wkt_string, ProgressTracker progress_tracker);
import_flags :同上
Type :同上
wkt_string :WKT字符串
progressTracker :null
1 public Point createPointFromWKT() throws IOException { 2 3 String wktString = "Point (-106.4453583 39.11775)"; 4 Geometry geom = OperatorImportFromWkt.local().execute(WktImportFlags.wktImportDefaults, Geometry.Type.Point, wktString, null); 5 6 return (Point)geom; 7 }
創建Point實例
1 PointLearn PointLearn = new PointLearn(); 2 Point p1 = PointLearn.createPoint(); 3 Point p2 = PointLearn.createPointFromWKT(); 4 Point p3 = PointLearn.createPointFromJson(); 5 Point p4 = PointLearn.createPointFromGeoJson();
Point 的數據存儲:
double[] m_attributes;
使用double數組存儲
Point 的常用方法:
數據操作
point .setAttribute(semantics) setX() setY() setZ() setM() setID() setXY() setXYZ() 設置屬性 均是對 m_attributes 的操作
point .getAttribute(semantics) getX() getY() getZ() getM() getID() 讀取屬性值 均是對 m_attributes 的操作
set的過程中會增加 addAttribute(semantics) get 的過程中會檢查 hasAttribute(semantics) 具體見 學習文檔(2)geometry
具體過程:
attributeIndex = m_description.getAttributeIndex(semantics); VertexDescription中規定了語義的位置,先查詢語義(X\Y\Z\M\ID)的規定位置
m_attributes[m_description._getPointAttributeOffset(attributeIndex) + ordinate] = value; 再根據查到的位置添加該位置的數據
拓撲操作
判斷相等(m_description結構相同 + m_attributes數據相同)
坐標轉換(二維仿射變換)
坐標轉換(三維仿射變換)
創建外接矩形 queryEnvelope
獲取邊界 getBoundary (return null 哈哈哈哈)
見 學習文檔(2)geometry
判斷數據狀態
p1.getType(); 類型
p1.getDimension(); 維度
p1.isEmpty(); 空值
p1.estimateMemorySize(); 消耗內存
見 學習文檔(2)geometry
p1.replaceNaNs 清空數據
p1.setEmpty(); 全部置空
復制操作:
opyTo(Geometry dst)
createInstance()
見 學習文檔(2)geometry
以上是對於Point的總結,希望大家交流學習,如有錯誤請在評論指出謝謝。
參考:http://esri.github.io/geometry-api-java/doc/Point.html
http://esri.github.io/geometry-api-java/javadoc/com/esri/core/geometry/Point.html