Skip to content

Instantly share code, notes, and snippets.

@ramshresh
ramshresh / multi2single.py
Created September 14, 2021 06:17 — forked from lptorres/multi2single.py
A simple script that converts shapefiles with multipart polygons into singlepart polygons, and copies the fields of the source shapefile. This script is based on a script by Paolo Corti, found here: https://gist.github.com/anonymous/735330 The original script only converts multipolygons by creating a new feature for each part of a multipolygon. …
import os
from osgeo import gdal, ogr, osr
import sys
def initFields(in_lyr, out_lyr):
#Arbitrarily get the first feature
feat = in_lyr[0]
#loop over each field
@ramshresh
ramshresh / multi2single_inplace.py
Created September 14, 2021 06:16 — forked from lptorres/multi2single_inplace.py
This script is similar to multi2single.py, but it converts the shapefile in place, instead of creating a new shapefile.
from osgeo import gdal, ogr
import sys
def multipoly2poly(layer):
for feature in layer:
fid = feature.GetFID()
geom = feature.GetGeometryRef()
if geom.GetGeometryName() == 'MULTIPOLYGON':
<?php
/**
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
* @param string $parameters SQL WHERE clause parameters *OPTIONAL*