Google Earth 匯入 KML 繪製格線 |
以每分為單位,替台灣地圖經緯度加上格線,並以KML檔案格式匯入Google Earth便於畫面呈現。
C程式原始碼 plotGridKML.c:
void main() {
float latCount, lngCount;
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
printf("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
printf(" <Document>\n");
printf(" <name>台灣絕對夠格</name>\n");
printf(" <description>從東經120.0~122.0, 北緯21.9~25.3, 每一分為區隔</description>\n");
printf(" <Style id=\"yellowLineGreenPoly\">\n");
printf(" <LineStyle>\n");
printf(" <color>7fffffff</color>\n");
printf(" <width>1</width>\n");
printf(" </LineStyle>\n");
printf(" <PolyStyle>\n");
printf(" <color>7f00ff00</color>\n");
printf(" </PolyStyle>\n");
printf(" </Style>\n");
printf(" <Placemark>\n");
printf(" <name>台灣絕對夠格</name>\n");
printf(" <description>從東經120.0~122.0, 北緯21.9~25.3, 每一分為區隔</description>\n");
printf(" <styleUrl>#yellowLineGreenPoly</styleUrl>\n");
printf(" <LineString>\n");
printf(" <extrude>1</extrude>\n");
printf(" <tessellate>1</tessellate>\n");
printf(" <altitudeMode>absolute</altitudeMode>\n");
printf(" <coordinates>\n");
for (latCount = 21.9; latCount <= 25.3; latCount=latCount+0.2) {
printf(" 120.0,%2.1f,2000\n", latCount);
printf(" 122.0,%2.1f,2000\n", latCount);
printf(" 122.0,%2.1f,2000\n", latCount+0.1);
printf(" 120.0,%2.1f,2000\n", latCount+0.1);
printf(" 120.0,%2.1f,2000\n", latCount+0.2);
}
printf(" 122.0,25.3,2000\n");
for (lngCount = 122.0; lngCount >= 120.2; lngCount=lngCount-0.2) {
printf(" %3.1f,25.3,2000\n", lngCount);
printf(" %3.1f,21.9,2000\n", lngCount);
printf(" %3.1f,21.9,2000\n", lngCount-0.1);
printf(" %3.1f,25.3,2000\n", lngCount-0.1);
printf(" %3.1f,25.3,2000\n", lngCount-0.2);
}
printf(" 120.0,21.9,2000\n");
printf(" </coordinates>\n");
printf(" </LineString>\n");
printf(" </Placemark>\n");
printf(" </Document>\n");
printf("</kml>\n");
}
利用GCC編譯完成後,執行
$ gcc plotGridKML.c -o plotGridKML
$ plotGridKML > grid.kml
再將 grid.kml 匯入 Google Earth 即可。
#
沒有留言:
張貼留言