我有一些形狀數據(熔合表和/或數據庫列中的一系列kml文件),我想將它與另一個包含緯度經度的表合併點。基本上我想要一些方法來確定一個給定的經緯度點是否包含在kml形狀的內部,如果是這樣,保存對該行的參考。 我雖然也許有一種方法可以在融合表內做到這一點,但如果沒有,也許有一種方法可以循環每個kml並測試是否包含經緯度點。我理解這並不是非常有效。 任何幫助,算法,服務等都會很棒。如何確定一個點是否位於kml或shape內
3
A
回答
3
Fusion Tables SQL API具有ST_INTERSECTS運算符,但只能找到CIRCLE或RECTANGLE中的點。 GMap V3有一個幾何庫,它有一個poly.containsLocation()方法,我認爲它可以用於任意多邊形。參見:GoogleMap geometry/poly library
P.S.我知道這不適合KML文件的工作,但他們確實含有可以變成GMAP多邊形
0
這可能是長久以來解決了多邊形點,但我也有類似的問題,我想我會後我的解決辦法。
我有兩個Fusion表i)地址&數據和ii)多邊形&數據。我希望能夠輕鬆地查詢以查找一個或多個多邊形內的所有地址。我可以通過我的映射網頁實時執行此操作,但決定最好事先查找相關的多邊形,然後使用此數據執行我的映射查詢(在Web界面中更快更輕鬆地指定多個多邊形)。
因此,我將我的表格i)導出到Google表單的地址中,並創建了一個簡短的腳本,用於檢查地址所在的多邊形並將其寫回到Google表單。然後我更新了我的融合表我)。
我有一個近3000個地址和2000個多邊形的數據集,所以它超時了幾次,並且有幾個地址錯誤,但這很容易解決,我只是將腳本設置爲從第一行開始運行尚未更新。請注意,如果這些多邊形彼此重疊,但這不會起作用,因爲它們是地理邊界;-)
我使用的代碼在下面,也在要點here上。您顯然需要更新表ID,並且可能需要使用OAuth(我不太瞭解,但是遵循Google的說明並完成)做了一些事情。
// replace with your fusion table's id (from File > About this table)
var TABLE_ID = 'xxxxxxxxxx';
// first row that has data, as opposed to header information
var FIRST_DATA_ROW = 2;
var FIRST_DATA_COLUMN = 11;
var LAT_COLUMN = 1;
var LNG_COLUMN = 2;
var SA2_COLUMN = 6;
var SA3_COLUMN = 7;
/**
* Uses a lat and lng data in google sheets to check if an address is within a kml polygon
* in a list of KML polygons in fusion (in this case ABS/ASGC SA2 and SA3 regions, but could be any polygon)
* the function then stores the ID/name of the relevant polygon in google sheets
* I could check this data in realtime as I render maps, but as it doesn't changed, figure its better to just record
* which polygon each address pertains to so its quicker and easier to search (in particular it mades it easier to write a query
* which identifies all the address within multiple polygons)
* in this case I had 3000 rows so it exceeded maximum execution times, so I just updated the first data row a couple of times
* when the execution time exceeded.
*/
function updateSA2ID() {
var tasks = FusionTables.Task.list(TABLE_ID);
var sqlResponse = '';
// Only run if there are no outstanding deletions or schema changes.
if (tasks.totalItems === 0) {
var sheet = SpreadsheetApp.getActiveSheet();
var latLngData = sheet.getRange(FIRST_DATA_ROW, FIRST_DATA_COLUMN, sheet.getLastRow(), sheet.getLastColumn());
i = 1;
// Loop through the current current sheet
for (i = 1; i <= latLngData.getNumRows(); i++) {
// cross reference to Fusion table
lat = latLngData.getCell(i,LAT_COLUMN).getValue();
lng = latLngData.getCell(i,LNG_COLUMN).getValue();
sqlString = "SELECT 'SA2 Code', 'SA3 Code' FROM " + TABLE_ID + " WHERE ST_INTERSECTS(geometry, CIRCLE(LATLNG(" + lat + ", " + lng + "),1)) ";
//Browser.msgBox('Lat ' + lat + ' Lng ' + lng + '; ' + sqlString, Browser.Buttons.OK);
sqlResponse = FusionTables.Query.sql(sqlString);
//Browser.msgBox('SQL Response ' + sqlResponse, Browser.Buttons.OK);
latLngData.getCell(i,SA2_COLUMN).setValue(sqlResponse.rows[0][0]); // set SA2
latLngData.getCell(i,SA3_COLUMN).setValue(sqlResponse.rows[0][1]); // set SA3
}
}
else {
Logger.log('Skipping row replacement because of ' + tasks.totalItems + ' active background task(s)');
}
};
相關問題
- 1. 確定點是否位於特定幾何區域內
- 2. Javascript - 確定用戶當前位置是否位於Google地圖的KML層內
- 3. 確定是否一組點位於一個規則的網格
- 4. 使用Google Maps API V3,確定標記是否位於KML層邊界內
- 5. 確定頂點是否位於相機的左側或右側
- 6. 確定點是否位於有界區域內的算法
- 7. 如何確定一個點是否是一個四邊形
- 8. 如何確定內存是否屬於堆或堆棧?
- 9. 如何知道點是否或多或少屬於一個圓?
- 10. 如何檢查一個點是否在KML多邊形(GIS Shapefile)
- 11. 如何確定一個多邊形是否在另一個內?
- 12. 如何確定一個元素是否「定位」?
- 13. 如何確定一系列點(或多邊形)是否在矩形區域內?
- 14. 確定一個點是否在路上
- 15. Redis或Mongo確定一個數字是否在範圍內?
- 16. 確定一個點是否在Raphael.js中的路徑元素內
- 17. 確定一個節點是否存在於HTMLAgiltyPack
- 18. 確定一個ElementFinder是否與一個定位器匹配
- 19. 如何確定一個頂點是否有奇數或偶數的outE()?
- 20. 確定一個節點是否與另一個節點重疊
- 21. 如何快速確定點(緯度和經度)是否在一個國家內?
- 22. 如何確定一個網頁是否有RSS或不在C#
- 23. 如何確定一個領域是否有焦點?
- 24. 確定點是否在多邊形內
- 25. 如何確定一個座標是否在mutilpolygon內?
- 26. 如何確定Task.Run是否在一個循環內完成
- 27. 如何找到一個點位於一條線或多邊形內
- 28. 如何確定地址是否位於地圖上的某些邊界內?
- 29. 如何確定鼠標光標是否位於控件中
- 30. 確定是否編譯ELF對象是32位或64位
豔光四射,這是一個很好的開始 – user379468 2012-04-13 14:56:54