Creating Giraffe Projects from a CSV
1. get projects in a .csv
- clean (no padding)
- with a column "address" (or "lat" and "lon" if available) to geocode
- with a column "name" which will be project name
2. upload as a vector layer <YOUR PROJECTS>.csv
3. add a parcel layer eg "Regrid"
4. step through below
/*
before we start:
1. get projects in a .csv
- clean (no padding)
- with a column "address" (or "lat" and "lon" if available) to geocode
- with a column "name" which will be project name
2. upload as a vector layer <YOUR PROJECTS>.csv
3. add a parcel layer eg "Regrid"
4. step through below
*/
const buffer = (await import('https://esm.run/@turf/buffer')).default;
const centroid = (await import('https://esm.run/@turf/centroid')).default;
const gi = await loadGiJs();
const sitePoints = await gi.getLayerContents('<YOUR PROJECTS>.csv');
sitePoints.features.forEach(async f => {
// adjust properties here eg set f.properties.name or f.properties.source = "Import <TODAY>"
// fix geocoding if necessary
const [sw, ne] = gi.map.getBounds().toArray();
const goog = await gi.gis.googleGeocode(f.properties.address, { bounds: `${sw[1]},${sw[0]}|${ne[1]},${ne[0]}` });
if (goog?.features?.[0]){
console.log("moved");
f.geometry = goog.features[0].geometry;
}
})
// add a temp layer to check in
gi.addTempLayerGeoJSON("sitePoints", sitePoints);
// join to regrid - backup just a 10m circle around the centroid
const left = sitePoints;
const right = await gi.getLayerContents('Regrid', false, left);
gi.gis.flatJoin(left, right, gi.gis.pointInsideJoin("ogc_fid"));
const byId = right.features.reduce((acc, f) => {
acc[f.properties.ogc_fid] = f;
return acc;
}, {});
left.features.forEach(f => {
// need to be polygons
if (byId[f.properties.ogc_fid]?.geometry && byId[f.properties.ogc_fid]?.geometry.type === 'Polygon') {
f.geometry = byId[f.properties.ogc_fid].geometry;
} else if (byId[f.properties.ogc_fid]?.geometry && byId[f.properties.ogc_fid]?.geometry.type === 'MultiPolygon') {
// just take first
f.geometry = {
type: "Polygon",
coordinates: byId[f.properties.ogc_fid].geometry.coordinates[0]
};
} else {
// backup - a 10m circle around the centroid
f.geometry = buffer(centroid(f), 10, {units: 'meters'}).geometry;
}
})
// to avoid duplicating
const synced = gi.syncToProjects(sitePolys, p => p.properties.name);
gi.shareWithTeam('<TEAM NAME>', gi.getProjects());
// add a temp layer to check in
gi.addTempLayerGeoJSON("sitePolys", left);
