1

I have an HTML file here, but I don't know how to extract the coordinate data into a GeoJSON or shapefile. Is there a quick way to get it? Link : https://codeshare.io/DZEwnO

...
function myMap() {
   ...
   };
   var features = [ 
               {
            position: new google.maps.LatLng(-6.970243, 110.423680),
            type: 'keluar',
            shelter: 'Kantor Pos Besar',
            status: 'KOTA',
            tipe: 'PERMANEN',
            arah: 'Tawang - Bawen',
            image: 'https://gis.perhubungan.jatengprov.go.id/assets/upload/shelter/thumbs/kantor_pos_besar.png'
         },
               {
            position: new google.maps.LatLng(-6.972159, 110.421801),
            type: 'keluar',
            shelter: 'Bata Pemuda',
            status: 'KOTA',
            tipe: 'Permanen',
            arah: 'Tawang - Bawen',
            image: 'https://gis.perhubungan.jatengprov.go.id/assets/upload/shelter/thumbs/H_Bata_Pemuda.png'
         },
               {
            position: new google.maps.LatLng(-6.975905, 110.418125),
            type: 'keluar',
            shelter: 'BCA Pemuda',
            status: 'KOTA',
            tipe: 'Permanen',
            arah: 'Tawang - Bawen',
            image: 'https://gis.perhubungan.jatengprov.go.id/assets/upload/shelter/thumbs/H_Bca_Pemuda.png'
         },
              ...```
3
  • 1
    In what way is your question connected with Leaflet since you use Google Maps JS API in your code? In please explain what do you mean by "quick way"?
    – TomazicM
    Mar 1, 2023 at 16:38
  • @TomazicM I'm sorry that I'm confused. I just want to get the coordinate data so that it can be a shapefile that I can use in ArcGIS or QGIS. Any suggestions for doing that Mar 1, 2023 at 16:43
  • 1
    Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works
    – Ian Turton
    Mar 1, 2023 at 16:46

1 Answer 1

2

You can simply iterate over features, create GeoJSON object and then download stringified GeoJSON.

Code could look something like this:

var geojson =  {
  "type": "FeatureCollection",
  "features": []
}

features.forEach(function(feature) {
  var geoJsonFeature = {
    "type": "Feature",
    "properties": {
      "type": feature.type,
      "shelter": feature.shelter,
      "status": feature.status,
      "tipe": feature.tipe,
      "arah": feature.arah,
      "image": feature.image
    },
    "geometry": {
      "type": "Point",
      "coordinates": [feature.position.lng(), feature.position.lat()]
    }
  }
  geojson.features.push(geoJsonFeature);
});
var data = new Blob([JSON.stringify(geojson)], {type: 'text/xml'});
var fileName = 'data.geojson';
if (navigator.appVersion.toString().indexOf('.NET') > 0)
   window.navigator.msSaveBlob(data, fileName);
else {
  var url = window.URL.createObjectURL(data);
  var downloadLinkElement = document.createElement('a');
  downloadLinkElement.href = url; 
  downloadLinkElement.download = fileName; 
  downloadLinkElement.click();
}

This is result viewed in https://geojson.io/:

enter image description here

2
  • Can you show me or give me the informaion to iterate over feature, becase im very new in this field, i only know about the GIS, not programmig, thanks Mar 2, 2023 at 0:56
  • 1
    Everything is shown in the above code. What is not clear?
    – TomazicM
    Mar 2, 2023 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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