Skip to main content

GeoJSON

Endpoint

POST https://api.geoflip.io/v1/transform/geojson

Payload Example

{
"input_geojson": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "id": 1, "group": "A" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-73.981, 40.768],
[-73.981, 40.769],
[-73.982, 40.769],
[-73.982, 40.768],
[-73.981, 40.768]
]
]
}
}
]
},
"output_format": "shp",
"output_crs": "EPSG:4326",
"transformations": [
{
"type": "buffer",
"distance": 100,
"units": "meters"
},
{
"type": "union"
}
]
}

Request example

<html>
<input type="file" id="fileInput" accept=".zip" />
<button id="uploadButton">Upload and Convert GeoJSON</button>
<a id="downloadLink" style="display:none;">Download Converted File</a>

<script>
document.getElementById('uploadButton').addEventListener('click', () => {
const payload = {
"input_geojson": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "id": 1, "group": "A" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-73.981, 40.768],
[-73.981, 40.769],
[-73.982, 40.769],
[-73.982, 40.768],
[-73.981, 40.768]
]
]
}
}
]
},
"output_format": "shp",
"output_crs": "EPSG:4326",
"transformations": [
{
"type": "buffer",
"distance": 100,
"units": "meters"
}
]
};

axios.post('https://api.geoflip.io/v1/transform/geojson',
payload,
{
headers: {
'Content-Type': 'application/json',
"apiKey": "YOUR_API_KEY" // Replace with your API key
},
responseType: 'blob' // To handle the response as a file since output is expected to be a .shp file
}
)
.then(response => {
const url = window.URL.createObjectURL(response.data);
const link = document.getElementById('downloadLink');
link.href = url;
link.download = 'converted_file.zip'; // Shapefiles returned as a zip file
link.style.display = 'block'; // Make the link visible
link.textContent = 'Download Converted File';
console.log("File converted successfully:", url);
})
.catch(error => {
console.error("Error converting file:", error);
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</html>

Explanation

The GeoJSON endpoint is a little bit different from the other endpoints since the input data can be provided in the payload as input_geojson, making the request simpler than the other reader endpoints that require a multipart form submission.

  • API Key: your geoflip api key must be provided in the request headers. You can create an apikey here.
  • Input GeoJSON: The input_geojson field must be a valid GeoJSON object.
  • Output Format: The output_format specifies the desired output, such as dxf, shp, etc.
  • Output CRS: The output_crs indicates the Coordinate Reference System you want the output to conform to (e.g., EPSG:4326).
  • Transformations: The transformations array allows you to apply operations such as buffering or union to the input data.

Requesting a GeoJSON output will return GeoJSON in the response body, but requesting a DXF, SHP, or GPKG will return a binary file in the response. Refer to the writer's section for examples on how to handle this response.

Key Considerations

  • GeoJSON can be provided in the request body using the input_geojson parameter.
  • GeoJSON is ideal when working with web-based spatial data due to its compatibility and simplicity.
  • Transformations, such as buffer, can add spatial context by expanding geometries, and operations like union can merge overlapping features.