MapXtreme for java 圖元和搜尋

來源:互聯網
上載者:User

地圖圖元是地圖上的一個地圖對象。如點、線或地區等。在 MapXtreme 中,地圖圖元表示為 Feature 對
象。

Feature 對象的方法
Feature 對象的方法包含有關製表和幾何資料的資訊。下表對列出了這些方法:
getAttribute 擷取賦予列索引的指定屬性。
getAttributeCount 擷取與此圖元相關的屬性數量。
getGeometry 擷取相關的幾何對象,如果圖元沒有幾何對象則為空白。
getLabelRendition 擷取為此圖元的標註指定的樣式。如果沒有用於該標註的樣式,則返回為空白。
getPrimaryKey 擷取用於此圖元的 PrimaryKey 對象(唯一 ID)。如果該圖元沒有
PrimaryKey,則將會返回空值。
getRaster 如果存在,則返回與該圖元關聯的柵格對象,如果圖元沒有柵格則返回為空白。
getRendition 返回此圖元的樣式。如果沒有用於該圖元的樣式,則返回為空白。每個 Feature 對象可有一個 Rendition 對象。Rendition 對象描述圖元的顯示特徵

程式碼範例: 從圖元擷取資訊

Layers layers = mapj.getLayers();Layer myLayer = layers.getLayer("hunan");// 擷取圖層table資訊TableInfo myTableInfo = myLayer.getTableInfo();// 儲存table 屬性欄位Vector<String> columnNames = new Vector<String>();int columnCount = myTableInfo.getColumnCount();String col;for (int j = 0; j < columnCount; j++) {col = myTableInfo.getColumnName(j);columnNames.addElement(col);}// 搜尋• searchAll,searchWithinRadius,searchWithinRegion,// searchWithinRectangle,searchAtPoint• searchByAttribute//queryParams 使用QueryParams 類來過濾這些資訊,以提高程式的效能//QueryParams queryParams = new QueryParams(true, false,true,true, true, true, SearchType.entire);//FeatureSet fs = layer.searchWithinRegion(cols,searchFeature.getGeometry(),  queryParams);RewindableFeatureSet features = new RewindableFeatureSet(myLayer.searchAll(columnNames, null));Feature fistF = features.getNextFeature();while (fistF != null) {Geometry geom = fistF.getGeometry();// Point:Geometry.TYPE_POINT=// 1,Line:Geometry.TYPE_LINE=2,Polygon:TYPE_REGION=3if (geom.getType() == Geometry.TYPE_POINT) {PointGeometry pntGeometry = (PointGeometry) geom;DoubleRect rect = pntGeometry.getBounds();DoublePoint dblPnt = pntGeometry.getCentroid();} else {VectorGeometry vectorGeometry = (VectorGeometry) geom;DoubleRect rect = vectorGeometry.getBounds();double[] pnts = null;int offset = 0;int numPts;for (int i = 0; i < vectorGeometry.getPointListCount(); ++i) {PointList pntList = vectorGeometry.getNextPointList();numPts = pntList.getPointCount();pnts = new double[numPts];// 座標資訊,存入數組pntList.getNextPoints(pnts, offset, numPts/2);}for (int j = 0; j < pnts.length; j++) {System.out.println(pnts[j]);}}fistF = features.getNextFeature();}


搜尋:使用搜尋功能可以按照地理資訊檢索特定的資料。例如,如果要尋找 25 米半徑範圍內的所有基站,那麼將執行搜尋操作。搜尋是 FeatureLayer 對象的方法。它們返回 FeatureSet 對象。MapXtreme 的準系統是選擇地圖上的圖元,以便可對其執行其它任務。使用者可以單擊地圖來選擇一個或多個圖元(點、線、地區等)。搜尋結果通常解釋為選擇內容。以下 Layer 對象的方法提供了各種搜尋圖層並返回 FeatureSet 集合的方式。
searchAll
searchWithinRadius
searchWithinRegion
searchWithinRectangle
searchAtPoint

(1)、searchAll 返回圖層中所有圖元的 FeatureSet 集合。如果應用程式需要迴圈整個圖層,可使用此搜尋方法。myLayer.searchAll(columnNames, QueryParams.ALL_PARAMS);(2)、searchWithinRadius 返回在點對象的指定距離之內構成圖元的 FeatureSet 集合。使用此搜尋可尋找離指定位置最近的餐飲,或者返回一家商店某一半徑範圍內的客戶數。DoublePoint dblPt = new DoublePoint(-73.889444, 42.765555);double dRadius = 10.03;FeatureSet fs = myLayer.searchWithinRadius(columnNames, dblPt, dRadius, LinearUnit.mile, QueryParams.ALL_PARAMS);(3)、searchWithinRegion 返回在一個圖元的幾何範圍內構成圖元的 FeatureSet 集合。使用此方法可返回特定地區(如郵遞區號)內的客戶數,或返回用 FeatureFactory 建立的地區內包含的圖元。Geometry vGeom = null;//某一個地區FeatureSet vfs = myLayer.searchWithinRegion(columnNames, vGeom, QueryParams.ALL_PARAMS); (4)、searchWithinRectangle 返回指定矩形邊界內的 FeatureSet 集合。使用此方法可在給定地圖視窗內進行搜尋或預檢縮放層級,以查看它是否包含某些要關注的點。DoubleRect dRect = new DoubleRect(-74.092662, 42.765555, -73.668898,42.856420);FeatureSet dfs = myLayer.searchWithinRectangle(columnNames, dRect,QueryParams.ALL_PARAMS);(5)、searchAtPoint 返回構成指定點上的圖元的 FeatureSet 集合。使用此方法可以測試與某個點 交叉的所有對象。DoublePoint dp = new DoublePoint(12.3456, -67.890);FeatureSet pfs = myLayer.searchAtPoint(columnNames, dp, QueryParams.ALL_PARAMS);(6)、searchByAttribute 返回其屬性與給定屬性相匹配的 FeatureSet 集合。使用此方法可以選擇帶有公用屬性資訊的所有圖元。例如,如果擁有一張包含家庭收入列的表,即可使用 searchByAttribute 來返回家庭收入等於 100,000 美元的所有記錄。Attribute mySearchAttr = new Attribute(100000);String searchCol = "Annual_Income";FeatureSet afs = myLayer.searchByAttribute(columnNames, searchCol, mySearchAttr, null);


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.