In my iOS application,I have one xml file with thousands of locations data. I need to convert it to kml format to show heat maps on my map view. How can I convert it? Please give me guidelines for this conversion...
<?xml version="1.0"?>
<row id="1">
<id>101</id>
<name>Sharon Appartments</name>
<longitude>115.23412</longitude>
<latitude>34.734121</latitude>
<city>Dallas</city>
<state>California</state>
<country>USA</country>
</row>
<row id="2">
.
.
.
.
<row id="20000">
.
.
</row>
</xml>
Since you asked for guidelines, an example kml document looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>New York City</name>
<description>New York City</description>
<Point>
<coordinates>-74.006393,40.714172,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
It seems you can keep the <name> field the same, you can combine the items in xml fields <city,<state>,<country> to klm field <address>city,state,country</address> or use it as a kml <description> tag (User-supplied content that appears in the description balloon ) as kml will use long and lat to determine a point if it is provided instead of using an address. Transform the xml <longitute>,<latitudite> need to be turned into a kml <point><cordinates>longitute,latatude</cordinates></point>
So you need to transform your klm document into something like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Sharon Appartments</name>
<description>Dallas, California, USA</description>
<Point>
<coordinates>115.23412,34.734121</coordinates>
</Point>
</Placemark>
<Placement>
Put item 2 details here
</Placement>
.
.
.
<Placement>
Put item 20000 details here
</Placement>
</Document>
</kml>
I got this from the https://developers.google.com/kml/documentation/kmlreference ,
Now for the heat map part, if you can transform your file into a list of lat and longs, you can put it into the python program on this webpage: http://jjguy.com/heatmap/ and it will produce a kml overlay for google maps based on that data, you need to combine that overlay with your kml file for your city data to get a complete map.
Related
I need to create code in Swift for iOS device, to create and save a local XML file. It's actually a KML file with waypoints for exporting to Google earth.
I found the API reference here: API Reference - Class - XMLDocument
But it lacks an example of how to use these functions. Other examples I find online are all in objective C, so I'm lost how to write the code.
If someone can show simple example of how to create the file and add some keys, childs etc, that would be awesome.
An example of what this KML output file will look like:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Waypoint Name.kml</name>
<StyleMap id="msn_ylw-pushpin">
<Pair>
<key>normal</key>
<styleUrl>#sn_ylw-pushpin</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_ylw-pushpin</styleUrl>
</Pair>
</StyleMap>
<Style id="sn_ylw-pushpin">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<ListStyle>
</ListStyle>
</Style>
<Style id="sh_ylw-pushpin">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<ListStyle>
</ListStyle>
</Style>
<Placemark>
<name>Waypoint Name</name>
<description>Description</description>
<LookAt>
<longitude>-114.4379986989632</longitude>
<latitude>62.47084160066127</latitude>
<altitude>0</altitude>
<heading>9.194188445440662e-10</heading>
<tilt>0</tilt>
<range>1000.000042077875</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin</styleUrl>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>-114.4435573708376,62.46869255035281,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Question: I have created a sample xml document containing data conforming to the atom 1.0 schema. When I import the contents of this file (for testing purposes) in PowerPivot, it creates columns for each atom element in each entry, instead of creating a column per content element. Why is this?
Background: A customer wants to import data from a web service which provides a feed that uses a custom XML schema that is not supported by PowerPivot. The service provides the ability for the caller to supply an XSLT template that will be applied to the feed. I am hoping to be able to transform this feed into a valid atom feed thereby allowing the customer to import data into PowerPivot.
Sample atom xml:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip>1234</d:Zip>
</content>
</entry>
</feed>
When imported into PowerPivot (selecting "From Data Feeds", clicking "Browse" and pointing out the xml file), it looks like this:
I was excpecting three columns: Name, Address and Zip. If I change "Include Atom Elements" from Auto to False in the connection configuration, no columns are imported.
It seems I was just missing the m:properties element. Final result - also includes examples of null attributes and data types:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<!-- attributes placed under the properties element -->
<m:properties>
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip m:type="Edm.Int32">1234</d:Zip>
<d:Comment m:null="true" />
</m:properties>
</content>
</entry>
</feed>
I have a small xml document from which I need to extract some values using xmllint. I am able to navigate through the xml hierarchy using xmllint --shell xmlfilename command.
But I am unable to extract the values. I don't want to use a grep / any pattern matching command, as that is already done and is a success.
I would appreciate any help regarding the xmlliint.
Here is my document in png format. I want to extract the 300$ and 500$ (the value).
<?xml version="1`.`0" encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics item="Mobile" name="Nokia" value="300$" />
<electronics item="Mobile" name="Sony" value="500$" />
</asset>
</adi>
Another doubt is, are the two sets, the different representation of same xml ?
<?xml version="1.0 encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics>
<item> Mobile </item>
<name>Nokia</name>
<value>300$</value>
</electronics>
<electronics>
<item> Mobile </item>
<name>Sony</name>
<value>500$</value>
</electronics>
</asset>
</adi>
With regards to your second question, those two snippets do not represent the same XML content. Attributes and child elements are not equivalent. A child element can be the root element of some arbitrary XML tree, but attributes are atomic.
E.g., I could modify the second snippet like this:
<?xml version="1.0 encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics>
<item>
Mobile
<sub-item>Phone</sub-item>
</item>
<name>Nokia</name>
<value>300$</value>
</electronics>
<electronics>
<item> Mobile </item>
<name>Sony</name>
<value>500$</value>
</electronics>
</asset>
</adi>
where I have added <sub-item>Phone</sub-item> to the first <item> element.
However, there's no equivalent if item is an attribute instead, as in the first snippet.
Late but while searches for the tag xmllint match the first page, I answer you now ;)
use --xpath instead of --xpath like below
xmllint --xpath '//electronics/value/text()' second-xml_file.xml
I have noticed that parseKml() function does not parse KML file correctly. For example, if you have this bit of KML:
<ExtendedData>
<Data name="Offer">
<value>Apples</value>
<value>Potatoes</value>
<value>Tomatoes</value>
</Data>
</ExtendedData>
The parseKml() function will return a kmlObject that will contain only the last value, i.e. "Tomatoes":
Does anyone have a solution for this?
The structure for the type of extended data you are using is for name/value pairs. i.e. a single name with a single value.
<ExtendedData>
<Data name="string">
<displayName>...</displayName> <!-- string -->
<value>...</value> <!-- string -->
</Data>
</ExtendedData>
So what you are trying will not work. If you wish to add an arbitrary XML Data structure to a KML Feature then you would do it like this.
<ExtendedData xmlns:offer="http://yourserver.com/namespace">
<offer:item>Apples</offer:item>
<offer:item>Potatoes</offer:item>
<offer:item>Tomatoes</offer:item>
</ExtendedData>
Based on the data structure, the 'offer' XML Schema file (http://yourserver.com/namespace) would be something like.
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="item" type="xsd:string" />
</xsd:schema>
I believe the <Data> element can only contain a single <value> - according to the docs, the "<Data> element allows you to add untyped name/value pairs to the user data associated with a given Feature."
So in your case, it's picking up the last <value> element only. You might find another way to add your custom data here: https://developers.google.com/kml/documentation/extendeddata
Using OmniXML and Delphi, I would like to locate an element and change another element in the node. For example, in the xml listing below, I would like to locate /first-name = 'Joe1' and then locate and change the /price from 1200 to 10.
I've tried using XPathSelect but I can not seem to specify the /first-name.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myfile.xsl" ?>
<bookstore specialty="novel">
<book style="autobiography">
<author>
<first-name>Joe1</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary Review Honorable Mention</award>
</author>
<price>1200</price>
</book>
<book style="textbook">
<author>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
<publication>Selected Short Stories of
<first-name>Mary</first-name>
<last-name>Bob</last-name>
</publication>
</author>
<editor>
<first-name>Britney</first-name>
<last-name>Bob</last-name>
</editor>
<price>55</price>
</book>
</bookstore>
Use //book[author/first-name = "Joe1" ] as your XPathSelect query to get the node, and then access the subnode Price from that node to change it.