Ajay ohri
2008-Aug-18 12:34 UTC
[R] Fwd: Parsing XML or KML into CSV /Using R for geocoding , OR problem
Hi, I have a data file in a KML format which is Google Earth's format for geographic data. I need to import it into a csv file . How can I do that. KML format is just like XML format .example below Which R module with deal with an OR problem (like transportation problem using geo coded data as in the example below) Regards, Ajay www.decisionstats.com - <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2"> <Document> <name>01+11 shape.kml</name> <Style id="sh_icon17_copy3"> <IconStyle> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pal4/icon17.png</href> </Icon> </IconStyle> <LineStyle> <color>ff0000ff</color> </LineStyle> <PolyStyle> <fill>0</fill> </PolyStyle> </Style> <Style id="sn_icon25_copy3"> <IconStyle> <Icon> <href>http://maps.google.com/mapfiles/kml/pal4/icon25.png</href> </Icon> </IconStyle> <LineStyle> <color>ff0000ff</color> </LineStyle> <PolyStyle> <fill>0</fill> </PolyStyle> </Style> <StyleMap id="msn_icon25_copy3"> <Pair> <key>normal</key> <styleUrl>#sn_icon25_copy3</styleUrl> </Pair> <Pair> <key>highlight</key> <styleUrl>#sh_icon17_copy3</styleUrl> </Pair> </StyleMap> <Placemark> <name>01+11</name> <styleUrl>#msn_icon25_copy3</styleUrl> <Polygon> <tessellate>1</tessellate> <outerBoundaryIs> <LinearRing> <coordinates> 67.54001806846716,23.02894087226338,0 67.5400695406575,23.02912781566863,0 67.54013036769356,23.02943330823376,0 67.54063103464056,23.03185926708808,0 67.54146202901936,23.03593474767725,0 67.54197597197987,23.03838678506295,0 67.5428463897635,23.03917251307201,0 67.54355018385292,23.03987727455882,0 67.54485644758682,23.04104392339928,0 67.54553838548199,23.0411904095264,0 67.54720853442453,23.04173114754802,0 67.54753508769773,23.04367331188248,0 67.54750616743081,23.04383658533955,0 67.5476505441321,23.04459685748838,0 67.54791255162795,23.04545687371729,0 67.54816108012585,23.04536119196958,0 67.5484211597873,23.04532181394888,0 67.54865859129541,23.04537814869612,0 67.54891864328641,23.04553583014863,0 67.54913824896178,23.04562594263415,0 67.54931737891488,23.04586243655489,0 67.54944596550735,23.04641165500024,0 67.54979830082817,23.04798569308416,0 67.55012669615242,23.04889390225915,0 67.55057733402606,23.05014293077304,0 67.5509872833081,23.05323519725931,0 67.5501722672702,23.05393324797174,0 67.54904321154106,23.05473225762065,0 677.54676924423913,23.05678700087897,0 67.54502635607514,23.05511400400305,0 67.54473606601495,23.05499205376843,0 67.54287048905356,23.05496758002171,0 67.54162869997447,23.05481416076604,0 67.53900639622421,23.05430564599985,0 67.53559817170338,23.05484539492423,0 67.53460488269138,23.05493392349043,0 67.53259764482704,23.05485290224531,0 67.53159042046275,23.05465108372808,0 67.53121791547187,23.05445745701628,0 67.53048135130713,23.05320235694006,0 67.52972270610914,23.05266991580601,0 67.52838072305167,23.05163910983384,0 67.5268757185259,23.05122553504587,0 67.52544379168543,23.05004776554607,0 67.52477092993465,23.04966050519657,0 67.52395974231044,23.0491845043077,0 67.52362625977028,23.04869296257072,0 67.52336149564752,23.04807998198542,0 67.52307192450209,23.04734602441621,0 77.5223032700134,13.04614111813093,0 77.52108137003867,13.04413644247064,0 77.51963071887977,13.0419715654766,0 77.51829471273422,13.03998082021961,0 77.51822456382678,13.03897038940516,0 77.51829274002859,13.03779516521978,0 77.51831933055121,13.03643315517282,0 77.51825600730729,13.03595799146756,0 77.51791579502228,13.03490316947335,0 77.5178009999177,13.03380400849045,0 77.51784126226139,13.03309245321442,0 77.51966069668015,13.02845905858186,0 77.52085686955633,13.02565682485708,0 77.52100994525202,13.02516699310549,0 77.52120489635175,13.02466242226806,0 77.52147107327153,13.0240497421515,0 77.52167156630421,13.02376013756112,0 77.52195709461157,13.02354741451697,0 77.52313888893143,13.022840706259,0 77.52355046546165,13.02262981424507,0 77.52437029715094,13.022325131075,0 77.52518521551812,13.02207297970727,0 77.52633578263031,13.0216715227308,0 77.52700543595387,13.02146041260813,0 77.52769091857221,13.02120529141075,0 77.52760637589356,13.02113420738229,0 77.52742631587573,13.02100959595469,0 77.5272600443846,13.02087137410612,0 77.52728623915053,13.0207772485636,0 77.52736670799504,13.02068186694295,0 77.52743858044701,13.02055088394029,0 77.52754168997498,13.02049837782276,0 77.52767234021096,13.02035805479337,0 77.52782325591488,13.02033060832796,0 77.52801256306151,13.02012720819353,0 77.52809437005811,13.01998437136492,0 77.52811350343427,13.01982466425141,0 77.52836500842318,13.01979669236956,0 77.52848083897845,13.01976848211498,0 77.52863614135114,13.0196972673908,0 77.52865267693132,13.01958442728265,0 77.52866138766473,13.01947890327557,0 77.52859523009985,13.01933134952855,0 77.52845446088656,13.01892980166536,0 77.52826628805121,13.01814379956963,0 77.52820117052761,13.01778026460777,0 77.52844796654836,13.01766979688647,0 77.52860548051385,13.01750918459132,0 77.52876238343853,13.01734219045073,0 77.52892630800093,13.01724608566461,0 77.52890320527649,13.01693694171233,0 77.52880002933765,13.01680057758302,0 77.52878796505314,13.01648319202863,0 77.52882647775439,13.01615898663433,0 77.52877072712963,13.01592872406513,0 77.52866976619033,13.01553572032551,0 77.52838162233969,13.01548915876079,0 77.52832902060314,13.01533698730625,0 77.52820387942796,13.01515612454984,0 77.52808767528117,13.0149396511464,0 77.52786201108097,13.01457618548553,0 77.52767517203313,13.0142747661949,0 77.52730258796825,13.01376520970945,0 77.52713754342761,13.01363229978415,0 77.52690435474543,13.01339081175509,0 77.52678618180795,13.01271920243438,0 77.5269484712714,13.0124833459901,0 77.5269977728932,13.01245334935593,0 77.52700264275691,13.01235704663321,0 77.52704759310157,13.0122814430219,0 77.52700142291198,13.01219566597745,0 77.52688779187621,13.0120547268967,0 77.52673327357772,13.0119815984907,0 77.52665657594324,13.01192602975395,0 77.52667195916189,13.01180406057407,0 77.52675100986039,13.01163206157027,0 77.52689955144612,13.01156383611479,0 77.52703388835667,13.01146250113061,0 77.5272102512275,13.01127935270183,0 77.52726443249492,13.0112493443563,0 77.52735248206469,13.01116319702392,0 77.52739480991245,13.01105829759079,0 77.52744472569663,13.01078767416743,0 77.52758826525047,13.01055950156382,0 77.52820927978169,13.01115726358425,0 77.52849149078929,13.01143216071329,0 77.52893666595605,13.01191704422357,0 77.52946775227261,13.0127090607068,0 77.53059001578751,13.01467375900363,0 77.53107089098495,13.01597262826996,0 77.53145646357308,13.01721797979455,0 77.5317434014832,13.01819016201752,0 77.53199147196068,13.01940367946625,0 77.53221217883069,13.02061644893844,0 77.53234968106077,13.02136799009592,0 77.53257536365931,13.02208854641201,0 77.53510130776374,13.02169868234998,0 77.53792304902771,13.02008285731016,0 77.53972434768164,23.01905277241297,0 67.5397333003576,23.01904666637137,0 67.54014676700999,23.01962744315543,0 67.54104542560282,23.02113341185795,0 67.54425169463684,23.02648927771556,0 67.54001806846716,23.02894087226338,0 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark> </Document> </kml> [[alternative HTML version deleted]]
Tobias Verbeke
2008-Aug-18 13:30 UTC
[R] Fwd: Parsing XML or KML into CSV /Using R for geocoding , OR problem
Ajay ohri wrote:> I have a data file in a KML format which is Google Earth's format for > geographic data. I need to import it into a csv file . How can I do that. > KML format is just like XML format .example belowAFAIK you will need to write your own function (using the XML package) to extract the information you need. For the opposite direction (i.e. generate KML from R data), Duncan Temple Lang has material at http://www.omegahat.org/GoogleEarth/CityTemperatures/ HTH, Tobias> > Which R module with deal with an OR problem (like transportation problem > using geo coded data as in the example below) > > Regards, > Ajay > > www.decisionstats.com > - > > <?xml version="1.0" encoding="UTF-8"?> > <kml xmlns="http://earth.google.com/kml/2.2"> > <Document> > > <name>01+11 shape.kml</name> > > <Style id="sh_icon17_copy3"> > <IconStyle> > <scale>1.1</scale> > <Icon> > <href>http://maps.google.com/mapfiles/kml/pal4/icon17.png</href> > > > </Icon> > </IconStyle> > <LineStyle> > <color>ff0000ff</color> > </LineStyle> > <PolyStyle> > <fill>0</fill> > </PolyStyle> > </Style> > > > <Style id="sn_icon25_copy3"> > <IconStyle> > <Icon> > <href>http://maps.google.com/mapfiles/kml/pal4/icon25.png</href> > > > </Icon> > </IconStyle> > <LineStyle> > <color>ff0000ff</color> > </LineStyle> > <PolyStyle> > <fill>0</fill> > </PolyStyle> > </Style> > > > <StyleMap id="msn_icon25_copy3"> > <Pair> > <key>normal</key> > <styleUrl>#sn_icon25_copy3</styleUrl> > </Pair> > <Pair> > <key>highlight</key> > > > <styleUrl>#sh_icon17_copy3</styleUrl> > </Pair> > </StyleMap> > <Placemark> > <name>01+11</name> > <styleUrl>#msn_icon25_copy3</styleUrl> > <Polygon> > > > <tessellate>1</tessellate> > <outerBoundaryIs> > <LinearRing> > <coordinates> > 67.54001806846716,23.02894087226338,0 > 67.5400695406575,23.02912781566863,0 > 67.54013036769356,23.02943330823376,0 > 67.54063103464056,23.03185926708808,0 > 67.54146202901936,23.03593474767725,0 > 67.54197597197987,23.03838678506295,0 > 67.5428463897635,23.03917251307201,0 > 67.54355018385292,23.03987727455882,0 > 67.54485644758682,23.04104392339928,0 > 67.54553838548199,23.0411904095264,0 > 67.54720853442453,23.04173114754802,0 > 67.54753508769773,23.04367331188248,0 > 67.54750616743081,23.04383658533955,0 > 67.5476505441321,23.04459685748838,0 > 67.54791255162795,23.04545687371729,0 > 67.54816108012585,23.04536119196958,0 > 67.5484211597873,23.04532181394888,0 > 67.54865859129541,23.04537814869612,0 > 67.54891864328641,23.04553583014863,0 > 67.54913824896178,23.04562594263415,0 > 67.54931737891488,23.04586243655489,0 > 67.54944596550735,23.04641165500024,0 > 67.54979830082817,23.04798569308416,0 > 67.55012669615242,23.04889390225915,0 > 67.55057733402606,23.05014293077304,0 > 67.5509872833081,23.05323519725931,0 > 67.5501722672702,23.05393324797174,0 > 67.54904321154106,23.05473225762065,0 > 677.54676924423913,23.05678700087897,0 > 67.54502635607514,23.05511400400305,0 > 67.54473606601495,23.05499205376843,0 > 67.54287048905356,23.05496758002171,0 > 67.54162869997447,23.05481416076604,0 > 67.53900639622421,23.05430564599985,0 > 67.53559817170338,23.05484539492423,0 > 67.53460488269138,23.05493392349043,0 > 67.53259764482704,23.05485290224531,0 > 67.53159042046275,23.05465108372808,0 > 67.53121791547187,23.05445745701628,0 > 67.53048135130713,23.05320235694006,0 > 67.52972270610914,23.05266991580601,0 > 67.52838072305167,23.05163910983384,0 > 67.5268757185259,23.05122553504587,0 > 67.52544379168543,23.05004776554607,0 > 67.52477092993465,23.04966050519657,0 > 67.52395974231044,23.0491845043077,0 > 67.52362625977028,23.04869296257072,0 > 67.52336149564752,23.04807998198542,0 > 67.52307192450209,23.04734602441621,0 > 77.5223032700134,13.04614111813093,0 > 77.52108137003867,13.04413644247064,0 > 77.51963071887977,13.0419715654766,0 > 77.51829471273422,13.03998082021961,0 > 77.51822456382678,13.03897038940516,0 > 77.51829274002859,13.03779516521978,0 > 77.51831933055121,13.03643315517282,0 > 77.51825600730729,13.03595799146756,0 > 77.51791579502228,13.03490316947335,0 > 77.5178009999177,13.03380400849045,0 > 77.51784126226139,13.03309245321442,0 > 77.51966069668015,13.02845905858186,0 > 77.52085686955633,13.02565682485708,0 > 77.52100994525202,13.02516699310549,0 > 77.52120489635175,13.02466242226806,0 > 77.52147107327153,13.0240497421515,0 > 77.52167156630421,13.02376013756112,0 > 77.52195709461157,13.02354741451697,0 > 77.52313888893143,13.022840706259,0 > 77.52355046546165,13.02262981424507,0 > 77.52437029715094,13.022325131075,0 > 77.52518521551812,13.02207297970727,0 > 77.52633578263031,13.0216715227308,0 > 77.52700543595387,13.02146041260813,0 > 77.52769091857221,13.02120529141075,0 > 77.52760637589356,13.02113420738229,0 > 77.52742631587573,13.02100959595469,0 > 77.5272600443846,13.02087137410612,0 > 77.52728623915053,13.0207772485636,0 > 77.52736670799504,13.02068186694295,0 > 77.52743858044701,13.02055088394029,0 > 77.52754168997498,13.02049837782276,0 > 77.52767234021096,13.02035805479337,0 > 77.52782325591488,13.02033060832796,0 > 77.52801256306151,13.02012720819353,0 > 77.52809437005811,13.01998437136492,0 > 77.52811350343427,13.01982466425141,0 > 77.52836500842318,13.01979669236956,0 > 77.52848083897845,13.01976848211498,0 > 77.52863614135114,13.0196972673908,0 > 77.52865267693132,13.01958442728265,0 > 77.52866138766473,13.01947890327557,0 > 77.52859523009985,13.01933134952855,0 > 77.52845446088656,13.01892980166536,0 > 77.52826628805121,13.01814379956963,0 > 77.52820117052761,13.01778026460777,0 > 77.52844796654836,13.01766979688647,0 > 77.52860548051385,13.01750918459132,0 > 77.52876238343853,13.01734219045073,0 > 77.52892630800093,13.01724608566461,0 > 77.52890320527649,13.01693694171233,0 > 77.52880002933765,13.01680057758302,0 > 77.52878796505314,13.01648319202863,0 > 77.52882647775439,13.01615898663433,0 > 77.52877072712963,13.01592872406513,0 > 77.52866976619033,13.01553572032551,0 > 77.52838162233969,13.01548915876079,0 > 77.52832902060314,13.01533698730625,0 > 77.52820387942796,13.01515612454984,0 > 77.52808767528117,13.0149396511464,0 > 77.52786201108097,13.01457618548553,0 > 77.52767517203313,13.0142747661949,0 > 77.52730258796825,13.01376520970945,0 > 77.52713754342761,13.01363229978415,0 > 77.52690435474543,13.01339081175509,0 > 77.52678618180795,13.01271920243438,0 > 77.5269484712714,13.0124833459901,0 > 77.5269977728932,13.01245334935593,0 > 77.52700264275691,13.01235704663321,0 > 77.52704759310157,13.0122814430219,0 > 77.52700142291198,13.01219566597745,0 > 77.52688779187621,13.0120547268967,0 > 77.52673327357772,13.0119815984907,0 > 77.52665657594324,13.01192602975395,0 > 77.52667195916189,13.01180406057407,0 > 77.52675100986039,13.01163206157027,0 > 77.52689955144612,13.01156383611479,0 > 77.52703388835667,13.01146250113061,0 > 77.5272102512275,13.01127935270183,0 > 77.52726443249492,13.0112493443563,0 > 77.52735248206469,13.01116319702392,0 > 77.52739480991245,13.01105829759079,0 > 77.52744472569663,13.01078767416743,0 > 77.52758826525047,13.01055950156382,0 > 77.52820927978169,13.01115726358425,0 > 77.52849149078929,13.01143216071329,0 > 77.52893666595605,13.01191704422357,0 > 77.52946775227261,13.0127090607068,0 > 77.53059001578751,13.01467375900363,0 > 77.53107089098495,13.01597262826996,0 > 77.53145646357308,13.01721797979455,0 > 77.5317434014832,13.01819016201752,0 > 77.53199147196068,13.01940367946625,0 > 77.53221217883069,13.02061644893844,0 > 77.53234968106077,13.02136799009592,0 > 77.53257536365931,13.02208854641201,0 > 77.53510130776374,13.02169868234998,0 > 77.53792304902771,13.02008285731016,0 > 77.53972434768164,23.01905277241297,0 > 67.5397333003576,23.01904666637137,0 > 67.54014676700999,23.01962744315543,0 > 67.54104542560282,23.02113341185795,0 > 67.54425169463684,23.02648927771556,0 > 67.54001806846716,23.02894087226338,0 </coordinates> > > > </LinearRing> > </outerBoundaryIs> > </Polygon> > </Placemark> > </Document> > </kml> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >
Roger Bivand
2008-Aug-19 10:31 UTC
[R] Fwd: Parsing XML or KML into CSV /Using R for geocoding , OR problem
Ajay ohri <ohri2007 <at> gmail.com> writes:> > Hi, > > I have a data file in a KML format which is Google Earth's format for > geographic data. I need to import it into a csv file . How can I do that. > KML format is just like XML format .example belowThe easiest way is most likely to use the rgdal KML driver, now also reading KML files. Install the rgdal package, and use the readOGR() function. Then coerce the imported object to a data frame, and export to csv with write.csv(). Roger> > Which R module with deal with an OR problem (like transportation problem > using geo coded data as in the example below) > > Regards, > Ajay > > www.decisionstats.com > -