GeoPackage
Endpoint
POST https://api.geoflip.io/v1/transform/gpkg
Payload Example (Multipart Form)
To submit a geopackage
file, the file must be provided in a multi-part form submission.
<html>
<input type="file" id="fileInput" accept=".gpkg" />
<button id="uploadButton">Upload and Convert GeoPackage</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); // GeoPackage file
const config = {
output_format: "dxf",
output_crs: "EPSG:4326",
transformations: [
{
type:"buffer",
distance: 100,
units: "meters"
}
]
};
formData.append('config', JSON.stringify(config));
axios.post('https://api.geoflip.io/v1/transform/gpkg', formData, {
headers: {
'Content-Type': 'multipart/form-data',
"apiKey": "YOUR_API_KEY"
},
responseType: 'blob' // Ensure the response is treated as a file since we have specified dxf as the output (blob)
})
.then(response => {
const url = window.URL.createObjectURL(response.data);
const link = document.getElementById('downloadLink');
link.href = url;
link.download = 'converted_file.dxf';
link.style.display = 'block'; // Make the link visible
link.textContent = 'Download Converted File';
})
.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 API key here.
-
Multipart Submission: GeoPackage files must be uploaded as a binary file within the
file
part of the multipart form. -
Config Component: The config component is where you define output details (
output_format
,output_crs
) and specify transformations. -
Transformations: Transformations can be specified in the request payload using the
transformations
parameter. This allows you to perform operations like clipping or buffering on the data. This must be provided as a list of objects. -
Output Format: The
output_format
can be one ofdxf
,shp
,geojson
, orgeopackage
. -
Output CRS: The
output_crs
can be any valid EPSG code, such asEPSG: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
-
GeoPackage is a modern alternative to Shapefile, offering greater flexibility and the ability to store multiple data layers.
-
Multipart form submission ensures that the binary GeoPackage file and its configurations are transmitted correctly.