Thanks in advance.
I'm trying to get the coordinates for the pins in this embedded Google Map: http://www.tcatbus.com/learn/system-map
Is there any way? I looked into KMZ extraction but was unable to find the file. Any other suggestions?
The KMZ format is a zipped KML, and KML is in turn XML. A "pin" is represented by a <point> within a <placemark> tag in the mark-up as follows:
<Placemark>
<name>Pin Name</name>
<description>Pin Description</description>
<Point>
<coordinates>-2.465543,51.280132,0 </coordinates>
</Point>
</Placemark>
You can extract the KML from a KMZ simply by unzipping it, or open in Google Earth and export as KML (the latter method has the advantage that it will validate the KMZ file in case what you have is not actually KMZ). A tutorial on KML is available here.
Related
I have about 140 KML files each containing a path and numerous pins along it. I want to open all the files but I need them to have different colors so that I can recognize where the paths intersect. How can I do this?
You can edit and assign different colors to each of your KML files. However, the simplest approach is using the random color mode in a line style added to each KML file.
<Document>
<Style id="s1">
<LineStyle>
<colorMode>random</colorMode>
</LineStyle>
</Style>
<Placemark>
<name>p1</name>
<styleUrl>#s1</styleUrl>
<LineString>
<coordinates>...</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>p2</name>
<styleUrl>#s1</styleUrl>
<LineString>
<coordinates>...</coordinates>
</LineString>
</Placemark>
...
</Document>
You could use a multi-file text editor such as NotePad++ to globally replace tag with tag plus the Style elements in all files. NotePad++ has a Find in Files option to search for files with targeted search and make changes in all matching files.
Is it possible to highlight a list of countries with a different colors?
I need to display some countries' statistics on the world map.
Now I use an image and fill a region with color (calculated for each country) by country's coordinates. It's a simple solution and it works well. But now I need to specify the countries' name too (and I think it's not the last customization).
There is a polygon solution, but it uses an array of coordinates. I don't think it's a suitable solution to highlight countries's territory.
I haven't found a solution yet. Any suggestions?
Thanks in advance.
Highlighting countries or regions to support statistics is known as Choropleth Mapping
, but unfortunately there usually isn't direct library support for Choropleth maps bundled into an online map API. This means you'll have to create your own framework, but fortunately it is possible to create one - I wrote an example using jQuery + HERE Maps to
answer the question here
Updated WKT solution now available
Access to KML shapes is no longer required, since the Geocoder API now offers an IncludeShapes attribute which returns the shape of a country in WKT format. A WKT parser can be found here.
A simple WKT choropleth example can be found here.
KML Base solution
For any framework you will need to have a file holding the boundaries of the countries or regions you need. The example uses a KML file, but you could also start with polygons if you had them. Country borders are a political minefield, which is the reason I guess most online mapping APIs steer clear of them. As a hint: try starting with something like http://geocommons.com/overlays/119819 and simplify it as much as possible to speed up the rendering- many small wiggles in the coast lines and small outlying islands are unnecessary.
Of course you could also try searching for "create choropleth map" from a search engine of your choice and use an tool to create a static image for your data (potentially at several zoom levels) and then use this as the basis of an map tile overlay. This requires a lot more work up front, but would push all the calculations server side and hence be faster to display.
Working example can be found on GitHub here
You could put the country's name into the image. It's not that difficult to place text into an image. The only tricky bit is if you are using tiles, you need to deal with names that cross tile boundaries by drawing the name once for each tile.
May I know how to determine the output of Bing map static image? Previously it used to be in png but now it is in jpeg. May I know how to revert back to png format?
Example: Display the image with the link below:
http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/space%20needle,seattle?mapLayer=TrafficFlow&mapVersion=v1&key=BingKey
The image is in jpeg. How to make it to png? Thanks.
I know it's a while you posted this question, but as there is no answer yet, and I got here via Google I'll supply an answer anyway.
You can use the format / fmt parameter.
From: http://msdn.microsoft.com/en-us/library/ff701724.aspx
One of the following image format values:
gif: Use GIF image format.
jpeg: Use JPEG image format. JPEG format is the default for Road, Aerial and AerialWithLabels imagery.
png: Use PNG image format. PNG is the default format for CollinsBart and OrdnanceSurvey imagery.
Examples:
format=jpeg
fmt=gif
I don't think you can request the image in a different format.
From http://msdn.microsoft.com/en-us/library/ff701724.aspx :
This URL returns an image in one of
the following formats:
PNG (image/png)
JPEG (image/jpeg)
GIF (image/gif)
You cannot specify the output format
for the map image. The image type is
chosen based on parameters such as
imagerySet.
If you really want a PNG, you could make the request from a server-side script and then construct a PNG file programmatically before serving that back to the client (using PHP's imagepng function, for example)
I'm using gmaps v3 and I am using a kml file to display polygon shapes.
What I want to do, is that if I have a LNG/LAT coordinate, how to find whether it falls on the boundary or inside the shape?
I understand you can do this with V2 maps but not V3. So then my questions are:
Can I import the coordinates into my db in a useful way that I can then do a select statement if the LNG/LAT falls in between?
Can I do something useful on the serverside end since I have all the data to hand anyway?
Any advice appreciated.
Thanks
Solved, I found a way of converting the kml file to lat/lng coordinates which I could then apply to a php function here: derivante.com/files/phpgis.txt
My goal is to display various shapes(polygons, points, linestring) on google maps by using data entered into a Postgis database dynamically(i mean by that we can see modifications in the map in real time).
I was looking for a way to do this that used the spatial structure already provided in postgis(already designating if shape is a linestring or polygon, etc) instead of parsing out the coordinates and then re-entering spatial structure in google maps. I saw that google maps api is now compatible with kml data formats. And then I read that i have to convert postgis data to kml format.
I've done some reading in the forums about the actual process of converting postgis data to kml via FWTools, but didn't see anything that would help me. I'm new to kml but am familiar with postgis and perl and PHP. Is there a tutorial for the process of converting postgis data to kml? Where can I get started? Thanks for any help
You can use PostGIS to convert to KML directly:
SELECT ST_AsKML(geometry) from MyTable;
ST_AsKML is one of several output formats, including WKT, GML, GeoJSON, etc.
To show dynamic data in Google Earth, a common pattern is to use KML with a NetworkLink element. Have the link's viewRefreshMode equal to onStop and Google Earth will make requests (to a URL served by PHP, presumably) with bounding box parameters attached. Use the bounding box to query features in the PostGIS database, and return results as kml. This is great if you have lots and lots of features, but only want to retrieve those in the region the user is looking at.
Depending on the complexity of your application, you may also want to look at GeoDjango. (Familiarity with PostGIS is a big head start!)
You can get a textual representation of the spatial data from a Postgres DB using a text conversion function, like
SELECT AsText(MyGemoetry) from MyTable
then you parse the string, create your objects using various API functions - depending on the PostGIS geometry type - and append these object to the main GE plugin object in a DOM like way.
If you are familiar with JavaScript and have a fundamental knowledge of XML, a good start is http://code.google.com/apis/earth/documentation/reference/
Don't forget to specify unique ID's to your objects so you can find them later to drop/modify.
Maybe you can get some inspirations here, display the linked "locator.js" file and look at function PaintSubField(Coord) ... this is another way, bit crude but effective, avoiding to mess around with too many individual parent/child objects and structures
You also may want to consult sample applications and use the code playground for "rapid prototyping"
re "realtime" you need at least an event that you can link your generation/redraw routines to.
Good luck
MikeD