2025-03-03     2025-03-04     2025-03-05

AT coordinates of postal code centroids are within postal code shapes

number of errors=5
number of warnings=0
country=AT
Group=chkGrpPostalCode

select 'http://qa.geonames.org/qa/kml/' || zip_code.countrycode || zip_code.zip || zip_code.placename || '.kml' as kml,zip_code.countrycode,admincode1,placename,zip, zip_code.geonameid,st_distance(wkb_geometry,st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326)) as distance,st_within(st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326),st_envelope(wkb_geometry)) as inbbox from zip_code,postalcode_shape where zip_code.countrycode=postalcode_shape.countrycode and zip=postalcode and not st_within(st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326),wkb_geometry) and zip_code.countrycode='AT' order by distance desc

Make sure the zip code is unique!
fix with st_centroid or ST_PointOnSurface
 create table tmp as select zip_code.countrycode,admincode1,placename,zip,st_distance(wkb_geometry,st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326)) as distance,st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326) as geom,wkb_geometry as polygon from zip_code,postalcode_shape where zip_code.countrycode=postalcode_shape.countrycode and zip=postalcode and not within(st_GeomFromText('Point(' || estlonglat[0] || ' ' || estlonglat[1] || ')',4326),wkb_geometry) and zip_code.countrycode='CA' order by distance desc;
update tmp set geom=st_centroid(wkb_geometry);
update tmp set geom=ST_PointOnSurface(polygon) where not st_within(geom,polygon);
update zip_code set estlonglat = point(st_x(geom), st_y(geom)) from tmp where tmp.zip=zip_code.zip and tmp.countrycode=zip_code.countrycode

kml	countrycode	admincode1	placename	zip	geonameid	distance	inbbox	
http://qa.geonames.org/qa/kml/AT1140Mauerbach.kml	AT	03	Mauerbach	1140	null	0.01834156278396343	f	
http://qa.geonames.org/qa/kml/AT1140Purkersdorf.kml	AT	03	Purkersdorf	1140	null	0.01834156278396343	f	
http://qa.geonames.org/qa/kml/AT1210Langenzersdorf.kml	AT	03	Langenzersdorf	1210	2772998	0.017685177864870665	f	
http://qa.geonames.org/qa/kml/AT1090Wien, Alsergrund.kml	AT	09	Wien, Alsergrund	1090	null	0.0027639044670550493	t	
http://qa.geonames.org/qa/kml/AT1080Wien, Josefstadt.kml	AT	09	Wien, Josefstadt	1080	null	0.0015880279459608382	f