Skip to main content

Shapefile

Endpoint

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

Payload Example (muiltipart Form)

To submit a Shapefile, first compress the .shp, .dbf, .shx, and .prj files into a single .zip archive. Example JavaScript code for a form submission:

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

<script>
document.getElementById('uploadButton').addEventListener('click', () => {
const selectedFile = document.getElementById('fileInput').files[0];
const formData = new FormData();
formData.append('file', selectedFile); // Zip file containing shapefile components

const config = {
output_format: "geojson",
transformations: [
{
type: "buffer",
distance: 100,
units: "meters"
}
]
};

formData.append('config', JSON.stringify(config));

axios.post('https://api.geoflip.io/v1/transform/shp', formData, {
headers: {
'Content-Type': 'multipart/form-data',
"apiKey": "YOUR_API_KEY"
}
})
.then(response => {
console.log("File converted successfully:", response.data);
})
.catch(error => {
console.error("Error converting file:", error);
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</html>

Explanation

  • API Key: your geoflip api key must be provided in the request headers. You can create an apikey here.

  • Multipart Submission: Shapefiles must be uploaded as a .zip due to their multi-file nature.

  • Config Component: The config component of the form is where you can define the output details (output_format, output_crs), and the file component is where you can provide the zipped Shapefile.

  • Transformations: transformations can be configured within the transformations paramater within the confi, this should provided as a list of objects. Read more about available geoflip transformations here

  • Output Format: The output_format can be one of dxf, shp, geojson, or geopackage.

  • Output CRS: The output_crs can be any valid EPSG code, such as EPSG:4326.

Note that requesting a binary file output (e.g., dxf, shp, geopackage) will return a blob in the response, while requesting a geojson output will return the required GeoJSON in the response body.

Key Considerations

  • Shapefiles are not ideal for large datasets due to their limitations, including a 2GB size limit and restrictions on attribute field names. However, they are a widely used format and supported in many desktop applications.

  • Make sure you include all the required files in the zipped shapefile payload.

  • Multipart form submission ensures all required components are transmitted together.