Jump to content

Recommended Posts

Posted

Hello everyone

Cloud you please help me? How to read and import coordinate from KML file

inside file has code:

.

Vatphiawat.kml

normal

#s_ylw-pushpin0

highlight

#s_ylw-pushpin_hl

1.3

http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png

1.1

http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png

Vatphiawat

#m_ylw-pushpin

1

102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0

Posted

If you just want to assume that the longitude and latitude given in the kml file are x and y coordinates in AutoCAD you can do the following. It may be a bit unorthodox but it works!

 

1. Set the point mode to something you can easily see. For example: pdmode 34

2. Copy and paste the longitude (x), latitude (y), and elevation values that are within the coordinates tags of the kml file into MS Word.

3. Use the replace command in Word and replace all spaces with ^ppoint . Note, there's a single space character after point. The ^p is the wild card for new paragraph. Make sure the first line also starts with point(space). Here’s a sample of what the file should look like at this point.

 

point 102.614364152051,17.95733901085014,0

point 102.6148784682264,17.95771822280192,0

point 102.6142663942859,17.95835128371222,0

point 102.6141224420007,17.95824935570436,0

point 102.6137704879814,17.95798561968717,0

point 102.614364152051,17.95733901085014,0

 

4. Save the Word file as a Plain Text file (.txt)

5. Change the file extension from .txt to .scr.

6. Give the script command in AutoCAD and open the .scr file you created above.

7. Zoom extents. You may need to regen to get the point symbol a decent size.

 

Using longitude and latitude of course are not true x,y coordinates. The scale of longitude values shrink as you move towards either pole. UTM coordinates provide less distortion but can cause additional problems if you are near the border of a UTM zone. UTM coordinates define a grid in kilometers.

 

If you don't have MS Word or another program that allows search and replace of the paragraph mark you will have to edit the file manually.

~Lee

Posted

This might get you going in the right direction

 

;Get the File Path
(setq fp (getfiled "Select XML File:" "" "xml" 16))

;Get the XML DOMDocument Object
(setq XML (vlax-create-object "MSXML.DOMDocument"))

;Load the XML File
(setq is_loaded (vlax-invoke-method XML 'load fp))

;Get the Coordinates Selection
(setq coords-sel (vlax-invoke-method XML 'getElementsByTagName "coordinates"))

;Get the Coords Element
(setq coords-Element (vlax-get-property coords-sel 'Item 0))

;Get the coords 
(setq coords (vlax-get-property (vlax-get-property coords-element 'nodetypedvalue) 'value))

 

I hope this helps

 

regards,

 

hippe013

 

P.S. May need to replace "xml" with "kml" in the getfiled function.

Posted

Thank you so much Lee

and Thank you so much hippe013 this was great code, but I think It has some thing wrong I will try it

 

This was code when I run it:

 

- Command: (setq fp (getfiled "Select XML File:" "" "kml" 16))

>>"D:\\Desktop\\Vatphiawat.kml"

- Command: (setq XML (vlax-create-object "MSXML.DOMDocument"))

>>#

- Command: (setq is_loaded (vlax-invoke-method XML 'load fp))

>>:vlax-true

- Command: (setq coords-sel (vlax-invoke-method XML 'getElementsByTagName "coordinates"))

>>#

- Command: (setq coords-Element (vlax-get-property coords-sel 'Item 0))

>>#

- Command: (setq coords (vlax-get-property (vlax-get-property coords-element 'nodetypedvalue) 'value))

>>; error: bad argument type: VLA-OBJECT #

 

It has something wrong at the end code.

Cloud you please help me? Thank you so much hippe013

Posted

Sorry. The last line of code should be:

 

(setq coords (vlax-variant-value (vlax-get-property coords-element 'NodeTypedValue)))

 

'coords' will be of string type.

 

regards,

 

hippe013

Posted

That's excellent Hippe013. Now am looking forward to create KML importer tool by getting help of this code. :thumbsup:

Posted

Right on! Be sure to post it here when you are done! :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...