-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Área e zona UTM no PostGIS #19
Comments
Sugestão adicional para aproveitar uso dos mapas: BoundsA função PostGIS St_Envelope devolve o equivalente a uma BBOX, que pode ser reduzida a uma lista de coordenadas extremas: min(x), max(x), min(y), max(y). Para evitar confusão, coluna
SELECT iso_3166_2, round(st_area(geom,true)/1000000) area_km2,
array_to_string( ST_Extent_geohash(geom,8) , ' ') as bbox_geohash
FROM ne_10m_admin_1_states_provinces
WHERE iso_3166_2 like 'BR-%' ORDER BY 1;
SELECT iso_3166_2,
(b->>'minlat')||' '||(b->>'maxlat') bounds_lat,
(b->>'minlon')||' '||(b->>'maxlon') bounds_long
FROM (
SELECT iso_3166_2, ST_Extent_jsonb(geom) b
FROM ne_10m_admin_1_states_provinces
WHERE iso_3166_2 like 'BR-%'
) t ORDER BY 1;
-- -- -- --
CREATE OR REPLACE FUNCTION ST_Extent_geohash(
p_geom geometry, -- input to get BBOX
p_len int DEFAULT 0, -- number of digits
p_srid int DEFAULT NULL -- tranform in other coordinate system, when negative use to set.
) RETURNS text[] AS $f$
SELECT array_agg(g)
FROM (
SELECT ST_GeoHash(geom,p_len) g
FROM ST_DumpPoints( ST_Envelope(CASE
WHEN p_srid IS NULL OR p_srid=0 THEN p_geom
WHEN p_srid<0 THEN ST_setsrid(p_geom,abs(p_srid))
ELSE ST_Transform(p_geom,p_srid)
END) ) t0
LIMIT 4
) t
$f$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION ST_Extent_jsonb(
-- Prefer to use to_jsonb(ST_Extent_array(geom)) or box2d().
-- This function is only to check ST_Envelope()
p_geom geometry, -- input to get BBOX
p_round_lat int DEFAULT NULL, -- decimal places to round latitude (0, 1, 2, ...)
p_round_lon int DEFAULT NULL, -- decimal places to round longitude (0, 1, 2, ...)
p_srid int DEFAULT NULL -- tranform in other coordinate system
) RETURNS JSONb AS $f$
SELECT jsonb_build_object('minlat',u[2], 'minlon',u[1], 'maxlat',u[4], 'maxlon',u[5])
FROM (
SELECT array_agg_cat( array[
CASE WHEN p_round_lon IS NULL THEN x ELSE round(x::numeric,p_round_lon)::float END,
CASE WHEN p_round_lat IS NULL THEN y ELSE round(y::numeric,p_round_lat)::float END
] ) u
FROM (
SELECT st_x(geom) x, st_y(geom) y
FROM ST_DumpPoints(ST_Envelope(CASE WHEN p_srid IS NULL THEN p_geom ELSE ST_Transform(p_geom,p_srid) END)) t0
LIMIT 3
) t1
) t2
$f$ LANGUAGE SQL IMMUTABLE; |
Usar shapes oficiais do IBGE atualizados em 29/06/2016. mkdir carga; cd carga;
wget ftp://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/Brasil/BR/br_unidades_da_federacao.zip
unzip br_unidades_da_federacao.zip
shp2pgsql BRUFE250GC_SIR.shp | psql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Complemento à issue #15, referente a área. A zona utm é um código com demanda ainda nos dias de hoje, e fácil de se obter a partir dos dados PostGIS, que podem ser de origem do OpenStreetMap ou outra fonte.
Teste com NaturalEarth-10m-cultural
wget https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip unzip ne_10m_admin_1_states_provinces.zip shp2pgsql ne_10m_admin_1_states_provinces.shp | psql postgres trydatasets
Resultados: problema com área, compare com Wikidata,
lib
The text was updated successfully, but these errors were encountered: