Skip to content

Instantly share code, notes, and snippets.

View capooti's full-sized avatar

Paolo Corti capooti

View GitHub Profile
import os
from osgeo import gdal
def rasterize(input_shp, out_raster):
# run gdal_rasterizer
layer_name = os.path.basename(input_shp).split('.')[0]
gdal_rasterize_cmd = f'gdal_rasterize -burn 1 -ts 1000 1000 -l {layer_name} {input_shp} {out_raster}'
print(gdal_rasterize_cmd)
import fiona
from shapely.geometry import shape, Point
def is_point_in_poly_with_iteration(shape_path, coords):
print(coords)
point = Point(coords)
with fiona.open(shape_path) as source:
for i, feat in enumerate(source):
if point.within(shape(feat['geometry'])):
print(f'Found it after checking {i} features!')
@capooti
capooti / kml2tiff.py
Created February 20, 2020 21:17
Generates a geotiff file from a kml with groundoverlays
import argparse
import os
import xmltodict
def do_kml2tiff_conversion(input_path, input_kml, output_path, output_tif):
with open(input_kml) as f:
doc = xmltodict.parse(f.read())

GeoNode 2.4 -> 2.10.1 migration

PostgreSQL

Create a role and a database for Django:

create role user with superuser login with password '***';
create database gn_24 with owner user;
\c gn_24
@capooti
capooti / export_geonode_maps.py
Created August 9, 2018 16:06
GeoNode: export title and url for all maps (run this from the Django shell)
import csv
from geonode.maps.models import Map
with open('maps_export.csv', mode='w') as export_file:
export_writer = csv.writer(export_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for map in Map.objects.all():
export_writer.writerow([map.title, map.get_absolute_url()])
@capooti
capooti / worldmap_nginx_sample.conf
Last active March 16, 2018 14:00
Sample configuration for GeoNode/WorldMap, GeoServer and Solr
server{
listen 80;
index index.html index.htm;
root /usr/share/nginx/html;
server_name example.com;
location /uploaded {
alias /home/ubuntu/worldmap_staging/worldmap_staging/uploaded/;
}
@capooti
capooti / solr_vs_rdbms.py
Last active March 10, 2018 22:58
Solr vs pycsw with RDBMS in WorldMap
import pysolr
from owslib.csw import CatalogueServiceWeb, PropertyIsEqualTo
import time
keywords = (
'agriculture',
'climate',
'farming',
'health',
'ocean',
@capooti
capooti / gist:77fb92ebaa505760488fbb524e917923
Created August 8, 2017 13:57
Solr search application template for FOSS4G 2017
{% extends "site_base.html" %}
{% load i18n %}
{% load url from future %}
{% block title %} {{ block.super }} {% endblock %}
{% block body_class %}Solr Search{% endblock %}
{% block body_outer %}
{% block body %}
<h3>Search Metadata</h3>
<form type="GET" action=".">
@capooti
capooti / fix_broken_map.py
Created December 1, 2016 16:37
Fix a broken map on GeoNode
import json
from geonode.maps.models import Layer, Map
map = Map.objects.get(id=2512)
for layer in map.layer_set.filter(ows_url__icontains='worldmap.harvard.edu/geoserver/wms'):
if layer.name is None:
print 'This layer is None!!!'
else:
print 'Fixing layer %s' % layer.name
cd /mydir
url="http://localhost:8080/geoserver/wms?STYLES=&FORMAT=image%2Fpng&TRANSPARENT=TRUE&LAYERS=geonode%3ADE01_SL6_22P_1T_20100521T010517_20100521T010602_DMI_0_1b5d_qXM&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LLBBOX=137.36632816178096,36.772883864884584,141.8751878470843,40.26195796778519&URL=http%3A%2F%2Flocalhost%3A8180%2Fgeoserver%2Fwms&TILED=true&TILESORIGIN=15291549.700982,4407496.8300991&SRS=EPSG%3A900913&BBOX=15654303.390625,4657155.2587109,15693439.149102,4696291.0171875&WIDTH=256&HEIGHT=256"
/usr/bin/curl $url --connect-timeout 5 --max-time 20 -s -f -o /dev/null
if [ $? -eq 0 ]
then
:
else