Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

All,

I have an attribute field formatted using HTML all ready to go for google earth markers.

The KML in question is here:

http://dl.dropbox.com/u/95231813/state_pts_MI.kml

Here is the value:

<div>
    Facility type: 
</div>
<div>
    Geoid: <a href="http://www.prisonersofthecensus.org/data/2010blocks/261450002001020/">261450002001020</a>
</div>
<div>
    County: Saginaw County
</div>
<div>
    2010 Correctional Population: 18
</div>

enter image description here

(i tried to paste the actual HTML but couldn't figure out how to display it as text rather than formatted html!!!)

I've love to have seperate attribute fields for the columns within that string:

Facility Type
County
2010 Correctional Population

How can this be done?

QGIS? LibreOffice? Python?

Thanks!!!

-mb

share|improve this question
    
If I read this correctly you want something like a table with one column the field names, the other the attribute values? –  om_henners Mar 28 '13 at 1:22
    
That's right, Om... –  mapBaker Apr 2 '13 at 16:03
2  
If you want your code to show up as a codeblock, you have to indent it 4 spaces. The easiest way is to paste your code in, then highlight it, then press Ctrl + k. This will automatically indent the whole block. For more info: gis.stackexchange.com/editing-help –  Jay Guarneri Apr 2 '13 at 16:29
    
Thank you, Jay! –  mapBaker Apr 2 '13 at 18:15
    
What do you mean by "seperate attribute fields"? How should they show up? Where? –  til_b Apr 3 '13 at 6:59
show 1 more comment

1 Answer

Assuming python and you want as a result a dict

{ "Facility Type" : None, 
  "Geoid": "<a ...",
  "County" : "Saginaw County",
  "2010 Correctional Population": 18
}

you could use

mystr = "<div>Facility type: </div><div>Geoid: <blah></div><div>County: Saginaw County</div><div>Pop: 18</div>"
parts = mystr.replace("<div>","").split("</div>")
r = {}
for part in parts:
    kv = part.split(":")

    if kv[0].strip() != "":
        r[kv[0]] = kv[1].strip()

Result is {'Facility type': '', 'County': 'Saginaw County', 'Geoid': '<blah>', 'Pop': '18'}

This does not handle the type conversion of the appropriate attributes, but that can be done.

share|improve this answer
    
Til_b - that is really confusing so I'll just post the KML ... –  mapBaker Apr 2 '13 at 16:04
    
thanks blah238 for the kind words... –  mapBaker Apr 2 '13 at 18:13
1  
At pastebin.com/1YsqZqbp I wrote a version that grabs the values directly from your KML. I am still not sure what you want to do, but you can do it now yourself. See for example the stuff I do with the results at the end of the paste. –  til_b Apr 3 '13 at 9:35
    
@til_b I greatly appreciate this! First off, what I'd ultimately be after is a CSV of the name, prisoner count, and lat, lon so I can replot / convert to SHP...this is a good learning tool for me, though, as I finally got aptana running as a python IDE to make your script work (thank you again!). If you have any thoughts about CSV creation, let me know. Anything helps, and as usual, teaches me a lot!!! Thank you again!!! –  mapBaker Apr 3 '13 at 15:29
1  
@mapBaker at pastebin.com/KKJj2Z2M there is a new version. This version also grabs the lat and lon values from the KML location element and stores them in the jail dict. For CSV Export jou just have to adapt line 59 (which prints the results in a specified format). –  til_b Apr 4 '13 at 9:07
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.