Reading / Parsing KML file in Java

2,574 views
Skip to first unread message

DhruvaSagar

unread,
Mar 4, 2009, 12:04:29 AM3/4/09
to KML Developer Support - Getting Started with KML
Hi everyone,

I am very new to kml files, I am looking to read/parse kml files and
extract certain information from the files.
Specifically I need to extract the <coordinates> from the file and
build an array of floats which I can then use to find if a point (x,y)
lies within that polygon.

I already have the simple logic of finding if the point lies within
the polygon, I already have the kml files.

I tried using the gekmllib, but that is not able to parse the kml
files and gives me NumberFormatException for the coordinates within
the file are in the form <coordinates>24.0000000,0 77.000000...

There is a 0 preceding certain locations that repeats periodically, I
do not know why they are there, the kml files that I am using are
generated using the google earth application so I am going to assume
that the kml files are perfectly formatted as they should be.

I am doing this for the site voteindia.in and it is an effort to find
the constituencies to which each user belongs but I am simply not able
to parse the kml files :(.

It is really urgent for me and I am going to try whatever I can to
simple parse these files and get the data that I need so any kind of
help is welcome. I am hoping some of the gurus here have a little time
to cater to this problem. I just need to parse the kml file, nothing
else.
Please help me!

Roman N

unread,
Mar 6, 2009, 2:39:21 PM3/6/09
to KML Developer Support - Getting Started with KML
Have you tried libkml? It has SWIG bindings for Java:

http://code.google.com/p/libkml/

I've used it in Python before with success--it should give you access
to the individual coordinate data.

- Roman
Reply all
Reply to author
Forward
0 new messages