Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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

The KML in question is here:

Here is the value:

    Facility type: 
    Geoid: <a href="">261450002001020</a>
    County: Saginaw County
    2010 Correctional Population: 18

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
2010 Correctional Population

How can this be done?

QGIS? LibreOffice? Python?



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... – DPSSpatial Apr 2 '13 at 16:03
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: – Jay Guarneri Apr 2 '13 at 16:29
Thank you, Jay! – DPSSpatial 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

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 ... – DPSSpatial Apr 2 '13 at 16:04
thanks blah238 for the kind words... – DPSSpatial Apr 2 '13 at 18:13
At 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!!! – DPSSpatial Apr 3 '13 at 15:29
@mapBaker at 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

Your Answer


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.