0

I am currently using leaflet.js to generate polygons and I would like to add them to my table in cartodb. I.e. a geojson object :

{
  "type": "Feature",
  "properties": {
    "name": "wing1"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -60.1171875,
          54.16243396806781
        ],
        [
          5.9765625,
          70.0205873017406
        ],
        [
          41.484375,
          49.15296965617039
        ],
        [
          11.25,
          1.0546279422758869
        ],
        [
          -60.1171875,
          54.16243396806781
        ]
      ]
    ]
  }
},

I am aware I can use the following api to insert new data to cartodb table.

https://{username}.carto.com/api/v2/sql?q=INSERT INTO test_table (column_name, column_name_2, the_geom) VALUES ('this is a string', 11, ST_SetSRID(ST_Point(-110, 43),4326))&api_key={api_key}

But can someone explain to me how I can send a geojson object using the existing api?

1

Instead of the CARTO SQL API, you can insert your geojson sample to a CARTO column value (geojson_data, for example). And then use the PostGIS ST_GeomFromGeoJSON and set the_geom to the result:

UPDATE 
  name_table
SET 
  the_geom = ST_GeomFromGeoJSON(geojson_data)

You will end up with this dataset/map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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