Wednesday, November 16, 2016

postgis import shape file output geojson

Create new database, must create postgis extension, otherwise would not import shape file.

run SQL:   CREATE EXTENSION postgis;

Enabling PostGIS

PostGIS is an optional extension that must be enabled in each database you want to use it in before you can use it. Installing the software is just the first step. DO NOT INSTALL it in the database called postgres.
Connect to your database with psql or PgAdmin. Run the following SQL. You need only install the features you want:
-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- Enable PostGIS Advanced 3D 
-- and other geoprocessing algorithms
-- sfcgal not available with all distributions
CREATE EXTENSION postgis_sfcgal;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- rule based standardizer
CREATE EXTENSION address_standardizer;
-- example rule data set
CREATE EXTENSION address_standardizer_data_us;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

=============================================================

import shape file by postgis import/export loader,

which is under program file, postgis folder,

when you import shape file to PostGIS, did you set SRID?
enter image description here
My example is srid=2230, the default is 0, you must manually type in. The postgis import manager did NOT recognize the esri xxx.prj file, which has projection info, if you open that file, you can NOT see srid=2230. There are 2 ways you can get srid= 2230.
1) go to http://prj2epsg.org/search , upload your xxx.prj file, it will search for it and show you result 2230.
2)Or you can use arcCatalog, right click shape file, choose properties, you can find WKID:2230
enter image description here
If you failed to manually set SRID, while import, no worry,
you can use sql to update SRID. By doing this, you set all geometry in this table srid=2230.
Note: no actual coordinate transformation occur, only update the metadata about SRID to 2230, default is 0.
For my case, I excute SQL:
   SELECT UpdateGeometrySRID('city_parks','geom',2230);
Finally, your geometry table has SRID=2230 Now you can output geojson to SRID=4326 by doing this:
   select st_asgeojson(st_transform(geom,4326)) from city_parks;
This is give you correct lat, long coordinate which you can put on any web map, google, bing, leaflet, openlayers...etc...
Previous solution also work, because st_setsrid will literally update each of your geometry srid to 2230.
     select st_asgeojson(st_transform(st_setsrid(geom,2230),4326)) from city_parks;
Summary:
You should manually set SRID while you import shape file, (in future, I hope POSTGIS import tool should automatically read esri's xxx.prj file and automatically popup the 2230 for me).
      If you forget to set SRID while import, you can always update your table's SRID metadata by SQL : 

            SELECT UpdateGeometrySRID('city_parks','geom',2230);
When you table's SRID is set correctly, you will be able to export to geojson by transform to SRID=4326.

Monday, November 7, 2016

apache server hangs


ServerRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.4"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the 
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen XX.XX.XX.XX:80
Listen 80
AcceptFilter http none
AcceptFilter https none


=================================

Fix:
Add this configuration snippet to Apache24/conf/httpd.conf (bottom of file seems fine):
# Apparently this fixes an issue with Apache 2.4.6 on Windows hanging
# when serving requests from Internet Explorer 10/11.
# see https://stijndewitt.wordpress.com/2014/01/10/apache-hangs-ie11/
AcceptFilter http none
AcceptFilter https none

AcceptFilter http none
AcceptFilter https none