1

I want ask is it possible for me to download the location detail (coordinate and location's name) of a map-based website?

I'm trying to get all the ports name and location from one of these websites

http://www.worldportsource.com/ports/TWN.php

or

https://www.searates.com/maritime/taiwan

if you open the website you can see there are some ports and I want to get all the name and its coordinate, in .kml format file, if possible.

Do you have any idea how to do this?

1 Answer 1

1

It looks like the data is stored in an object called jPortData. So what you can do is write some code in the Javascript Console (e.g.: in Chrome).

Run this code:

// Create root geojson FeatureCollection
const root = {
  "type": "FeatureCollection",
  "features": []
}

// Loop the port data and create a geojson feature for each port
jPortData.forEach((portData) => {
    root.features.push({
      "type": "Feature",
      "id": portData.id,
      "properties": {
        ...portData
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          parseFloat(portData.lng),
          parseFloat(portData.lat)
        ]
      }
    });
});

// Log the result stringified to the console
console.log(JSON.stringify(root,null,2));

So now we have your data as geojson. You could now save the result in a text file and open it in QGIS and convert it to KML. Another option would be to copy the result to geojson.io. There you can also export your data as KML.

Geojson.io Result

You can directly copy the output to your clipboard in Chrome using the copy function.

// Copy to clipboard
copy(JSON.stringify(root,null,2));
1
  • hi @bloigge and polygeo thank you for you help. you help me save a lot of time. i hope you have a nice day. thank you
    – Josh
    Commented Apr 13, 2022 at 2:17

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