You are on page 1of 13

Fredy Garzon mi tel,4537497 y el celu es3014306826

3364741 ajp
oswaldo Arenas
ungeop@gmail.com
carlop1978@hotmail.com Lopez Misael ()
$$$$$$$$$$$$$$$$$ sql queryes
--Proyecto Putumayo
--Area total coca 2004

select sum(area(transform(the_geom,32618))) as "Area total coca 2004"


from coca_putumayo_2004
--area total coca 2005
select sum(area(transform(the_geom,32618))) as "Area total coca 2005"
from coca_putumayo_2005
--Con funcion de redondear el resultado
select round(sum(area(transform(the_geom,32618)))) as "Area total coca 2005"
from coca_putumayo_2005
--consultar topdos los municipios de mi tabla
select * from municipalidad;
Consultar las areas de coca por municipio
select m.nombre, round(sum(area(transform(intersection(c.the_geom, m.the_geom),3
2618)))) as area_municipios from coca_putumayo_2004 as c,municipalidad as m wher
e
m.dept='Putumayo'
and c.the_geom && m.the_geom
group by
m.nombre
---se agrupo la misma consulta anterior de forma descendente
select m.nombre, round(sum(area(transform(intersection(c.the_geom, m.the_geom),3
2618)))) as area_municipios
from coca_putumayo_2004 as c,municipalidad as m where
m.dept='Putumayo'
and c.the_geom && m.the_geom
group by
m.nombre
order by area_municipios desc
-----consulta con vista
create view coca_municipios_putumayo as
select m.nombre, round(sum(area(transform(intersection(c.the_geom, m.the_geom),3
2618)))) as area_municipios
from coca_putumayo_2004 as c,municipalidad as m where
m.dept='Putumayo'
and c.the_geom && m.the_geom
group by
m.nombre
order by area_municipios desc
---en esta consulta se le dio la orden de mostrar las coordenadas para luego vis
ualizarlo
---con vista
---el askml se hace para visualizar los datos en google earth
select m.nombre, round(sum(area(transform(intersection(c.the_geom, m.the_geom),3
2618)))) as area_municipios,askml(m.the_geom)
from coca_putumayo_2004 as c,municipalidad as m where
m.dept='Putumayo'
and c.the_geom && m.the_geom
group by
m.nombre,askml(m.the_geom)
order by area_municipios desc

%%%%%%%%%% dia 4

-- seleccionmos las vias del departamento de antioqui ojo con el *


select a.admin_name,b.* from departamentos as a, vias as b
where
a.admin_name='Antioquia'
and
a.the_geom && b.the_geom
and
intersects(a.the_geom , b.the_geom);

-- ojo con las funciones de agregacion, debemos agrupar


select a.admin_name,b.layer,count(b.layer)
from departamentos as a, vias as b
where
a.admin_name='Antioquia'
and
a.the_geom && b.the_geom
and
intersects(a.the_geom , b.the_geom)
group by a.admin_name, b.layer
;
-- calcular las areas pero primero hacemos la transformacion a (UTM ZONA 18) , i
D= 32618 escojemos los que tocas
-- sin importar si el segmento este solo un pedazo lo cuenta en su totalidad
select a.admin_name,b.layer,sum(length(transform(b.the_geom,32618)))
from departamentos as a, vias as b
where
a.admin_name='Antioquia'
and
a.the_geom && b.the_geom
and
intersects(a.the_geom , b.the_geom)
group by a.admin_name, b.layer
;

-- ahora vamos a cortar los pedazos que esten por fuera de antioquia y solo cont
amos las distancias de adentro
select a.admin_name,b.layer,sum(length(transform(intersection(a.the_geom,b.the_
geom),32618)))
from departamentos as a, vias as b
where
a.admin_name='Antioquia'
and
a.the_geom && b.the_geom
group by a.admin_name, b.layer
;
-- selecccionamos todas las vias por dto
select a.admin_name,b.layer,sum(length(transform(intersection(a.the_geom,b.the_
geom),32618)))
from departamentos as a, vias as b
where
a.the_geom && b.the_geom
group by a.admin_name, b.layer
;

----------------------
Select AsKML(transform(buffer(transform(GeomFromText('POINT(-73.41941619116963
5.56709984295124)', 4326),32618),20000),4326)) as kmlpoly,
descriptor, sum(length(transform(intersection(the_geom,transform(buffer(transfor
m(GeomFromText('POINT(-73.41941619116963 5.56709984295124)', 4326),32618),20000)
,4326)),32618))) as length
from vias where the_geom && transform(buffer(transform(GeomFromText('POINT(-73.4
1941619116963 5.56709984295124)', 4326),32618),20000),4326)
GROUP by kmlpoly,descriptor;

-- recuperar datos dentro de ua caja


select *from vias where the_geom && SetSrid('BOX3D(-78 3, -76 5)'::box3d,4326);
-- recupera centroides de las cajas
select nombre, ASKML(centroid(the_geom))
from parques
where centroid(the_geom) && SetSrid('BOX3D(-78 3, -76 5)'::box3d,4326)
and
intersects(centroid(the_geom),SetSrid('BOX3D(-78 3, -76 5)'::box3d,4326))
%%%%%%%%%%%
$$$$$$$$$$$$$$
pgsql2shp -f c:\ambiental\sss.shp -h localhost -u ramsanjo -P india007 -g the_ge
om borra coca
pgsql2shp -f C:\ms4w\apps\geos\datos\catastro\vias.shp -h localhost -u ramsanjo
-P india007 -g the_geom borra coca
Active code page: 1252
pgsql2shp -f C:\ms4w\apps\geos\datos\medellin\barrios.shp -h localhost -u ramsan
jo -P xxxx -g the_geom borra barrios_medellin
shp2pgsql -s 4326 -I -W LATIN1 C:\ambiental\coca_antioquia_cauca.shp coca_cauca_
antioquia> c:\ambiental\coca_aa.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\AMBIENTAL\fronteras\acuerdos_geo.shp fronteras
> C:\AMBIENTAL\fronteras\fronteras.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\AMBIENTAL\fronteras\limte_fronterizo_geo.shp l
imites_fronterizos> C:\AMBIENTAL\fronteras\limites_fronterizos.sql

pgsql2shp -f C:\ms4w\apps\geos\datos\ambiental\aridez.shp -h localhost -u ramsan


jo -P india007 -g the_geom borra aridez
pgsql2shp -f C:\ms4w\apps\geos\datos\ambiental\precipitacion.shp -h localhost -u
ramsanjo -P india007 -g the_geom borra precipitacion
pgsql2shp -f C:\ms4w\apps\geos\datos\ambiental\precipitacion.shp -h localhost -u
ramsanjo -P india007 -g the_geom borra precipitacion
convertir imagenes mapserver
shp2img -m global.map -o mymap.png -i PNG
shp2img -m C:\ms4w\apps\geos\biomas.map -o C:\AMBIENTAL\biomas.png -i PNG
SELECT gid, objectid_1, objectid, cataridez, area, area_ha, the_geom FROM aridez
;
pgsql2shp -f C:\a\coca_2001.shp -h myserver -u apguser -P apgpassword -g thegeom
mygisdb "select town, geomunion(the_geom) as thegeom from towns group by town"
pgsql2shp -f C:\a\shp\biomas.shp -h localhost -u cauca -P 123456 -g the_geom geo
scire "SELECT gid, codane, sensor, imagen, fecha, areacoca, ano, the_geom FROM
coca where ano = '2000'"
pgsql2shp -f "/path/to/jpnei" -h myserver -u apguser -P apgpassword mygisdb
"SELECT neigh_name, the_geom FROM neighborhoods WHERE neigh_name = 'Jamaica Plai
n'"
shp2pgsql -s 4326 -I -W LATIN1 C:\data gis\simci\ultimos parques\ultimos_parques
_geo.shp parques_naturales> c:\ambiental\p_naturales.sql
psql -d nombre_de_database -f nombre_de_archivo_sql -U nombre_usuario
psql -d borra -f c:\ambiental\p_naturales.sql -U ramsanjo
psql -d borra -f C:\AMBIENTAL\fronteras\limites_fronterizos.sql -U ramsanjo
psql -d borra -f C:\AMBIENTAL\cauca_geoscire\catastral\nombres.sql -U ramsanjo

shp2pgsql -s 4326 -I -W LATIN1 C:\AMBIENTAL\cauca_geoscire\socioeconomico\agrope


cuario\agricola\cultivos_permanentes\yuca2003_2005_puntos.shp yuca2003_2005_punt
os> C:\AMBIENTAL\cauca_geoscire\socioeconomico\agropecuario\agricola\cultivos_p
ermanentes\yuca2003_2005_puntos.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\AMBIENTAL\cauca_geoscire\catastral\nombres.shp
c_urbano_nombres> C:\AMBIENTAL\cauca_geoscire\catastral\nombres.sql

shp2pgsql -s 4326 -I -W LATIN1 C:\AMBIENTAL\cauca_geoscire\socioeconomico\agrope


cuario\agricola\cultivos_permanentes\yuca2003_2005_puntos.shp yuca2003_2005_punt
os> C:\AMBIENTAL\cauca_geoscire\socioeconomico\agropecuario\agricola\cultivos_p
ermanentes\yuca2003_2005_puntos.sql
pgsql2shp -f C:\a\shp\biomas.shp -h localhost -u cauca -P 123456 -g the_geom geo
scire biomas
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\almaguer.shp alm


aguer> C:\a\almaguer.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\ALMAGUER_URBANO.
shp almaguer_urbano> C:\a\almaguer_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\argelia.shp arge
lia> C:\a\argelia.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\ARGELIA_URBANO.s
hp argelia_urbano> C:\a\argelia_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\balboa.shp balbo
a> C:\a\balboa.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\BALBOA_URBANO.sh
p balboa_urbano> C:\a\balboa_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\bolivar.shp boli
var> C:\a\bolivar.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\BOLIVAR_URBANO.s
hp bolivar_urbano> C:\a\bolivar_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\florencia.shp fl
orencia> C:\a\florencia.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\jambalo.shp jamb
alo> C:\a\jambalo.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\la_sierra.shp la
_sierra> C:\a\la_sierra.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\LA_SIERRA_URBANO
.shp la_sierra_urbano> C:\a\la_sierra_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\la_vega.shp la_v
ega> C:\a\la_vega.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\LA_VEGA_URBANO.s
hp la_vega_urbana> C:\a\la_vega_urbana.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\mercaderes.shp m
ercaderes> C:\a\mercaderes.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\MERCADERES_URBAN
O.shp mercaderes_urbano> C:\a\mercaderes_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\paez.shp paez>
C:\a\paez.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\patia.shp patia>
C:\a\patia.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\PATIA_URBANO.shp
patia_urbano> C:\a\patia_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\piendamo.shp pie
ndamo> C:\a\piendamo.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\popayan.shp popa
yan> C:\a\popayan.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\POPAYAN_URBANO.s
hp popayan_urbano> C:\a\popayan_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\rosas.shp rosas>
C:\a\rosas.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\san_sebastian.sh
p san_sebastian> C:\a\san_sebastian.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\SAN_SEBASTIAN_UR
BANO.shp san_sebastian_urbano> C:\a\san_sebastian_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\silvia.shp silvi
a> C:\a\silvia.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\sotara.shp sotar
a> C:\a\sotara.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\sucre.shp sucre>
C:\a\sucre.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\SUCRE_URBANO.shp
sucre_urbano> C:\a\sucre_urbano.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\timbio.shp timbi
o> C:\a\timbio.sql
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\catastro\toribio.shp tori
bio> C:\a\toribio.sql
psql -d borra -f C:\a\almaguer.sql -U ramsanjo
psql -d borra -f C:\a\almaguer_urbano.sql -U ramsanjo
psql -d borra -f C:\a\argelia.sql -U ramsanjo
psql -d borra -f C:\a\argelia_urbano.sql -U ramsanjo
psql -d borra -f C:\a\balboa.sql -U ramsanjo
psql -d borra -f C:\a\balboa_urbano.sql -U ramsanjo
psql -d borra -f C:\a\bolivar.sql -U ramsanjo
psql -d borra -f C:\a\bolivar_urbano.sql -U ramsanjo
psql -d borra -f C:\a\florencia.sql -U ramsanjo
psql -d borra -f C:\a\jambalo.sql -U ramsanjo
psql -d borra -f C:\a\la_sierra.sql -U ramsanjo
psql -d borra -f C:\a\la_sierra_urbano.sql -U ramsanjo
psql -d borra -f C:\a\la_vega.sql -U ramsanjo
psql -d borra -f C:\a\la_vega_urbana.sql -U ramsanjo
psql -d borra -f C:\a\mercaderes.sql -U ramsanjo
psql -d borra -f C:\a\mercaderes_urbano.sql -U ramsanjo
psql -d borra -f C:\a\paez.sql -U ramsanjo
psql -d borra -f C:\a\patia.sql -U ramsanjo
psql -d borra -f C:\a\patia_urbano.sql -U ramsanjo
psql -d borra -f C:\a\piendamo.sql -U ramsanjo
psql -d borra -f C:\a\popayan.sql -U ramsanjo
psql -d borra -f C:\a\popayan_urbano.sql -U ramsanjo
psql -d borra -f C:\a\rosas.sql -U ramsanjo
psql -d borra -f C:\a\san_sebastian.sql -U ramsanjo
psql -d borra -f C:\a\san_sebastian_urbano.sql -U ramsanjo
psql -d borra -f C:\a\sotara.sql -U ramsanjo
psql -d borra -f C:\a\sucre.sql -U ramsanjo
psql -d borra -f C:\a\sucre_urbano.sql -U ramsanjo
psql -d borra -f C:\a\timbio.sql -U ramsanjo
psql -d borra -f C:\a\toribio.sql -U ramsanjo
# 17 09 2008
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\economico\red_vial.shp re
d_vial> C:\a\red_vial.sql
psql -d borra -f C:\a\red_vial.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\ambiental\geologia.shp ge
ologia> C:\a\geologia.sql
psql -d borra -f C:\a\geologia.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\ambiental\orografia.shp o
rografia> C:\a\orografia.sql
psql -d borra -f C:\a\orografia.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\economico\minifundio.shp
minifundio> C:\a\minifundio.sql
psql -d borra -f C:\a\minifundio.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\ambiental\mun_cauca.shp m
un_cauca> C:\a\mun_cauca.sql
psql -d borra -f C:\a\mun_cauca.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\ambiental\regiones.shp re
giones> C:\a\regiones.sql
psql -d borra -f C:\a\regiones.sql -U ramsanjo

shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\orden_publico\municipios_


expulsores.shp municipios_expulsores> C:\a\municipios_expulsores.sql
psql -d borra -f C:\a\municipios_expulsores.sql -U ramsanjo
MINERIA @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\socioeconomico\mineria\me
tales_preciosos.shp metales_preciosos> C:\a\metales_preciosos.sql
psql -d borra -f C:\a\metales_preciosos.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\socioeconomico\mineria\mi
nerales.shp minerales> C:\a\minerales.sql
psql -d borra -f C:\a\minerales.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\socioeconomico\mineria\so
licitudes_mineras_tramite.shp solicitudes_mineras_tramite> C:\a\solicitudes_min
eras_tramite.sql
psql -d borra -f C:\a\solicitudes_mineras_tramite.sql -U ramsanjo

shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\socioeconomico\mineria\ti


tulaciones_mineras_registradas.shp titulaciones_mineras_registradas> C:\a\titul
aciones_mineras_registradas.sql
psql -d borra -f C:\a\titulaciones_mineras_registradas.sql -U ramsanjo
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\geos\datos\socioeconomico\mineria\ZO
NAS_POTENCIALES_MINERAS.shp zonas_potenciales_mineras> C:\a\zonas_potenciales_m
ineras.sql
psql -d borra -f C:\a\zonas_potenciales_mineras.sql -U ramsanjo
############## cultura y sociedad
shp2pgsql -s 4326 -I -W LATIN1 C:\a\cauca_geoscire\cultura_sociedad\resguardos_g
eo.shp resguardos_cauca> C:\a\resguardos_cauca.sql
psql -d borra -f C:\a\resguardos_cauca.sql -U ramsanjo -P india007
###################################### srid colombia
EPSG:3114: MAGNA-SIRGAS / Colombia Far West zone
EPSG:3115: MAGNA-SIRGAS / Colombia West zone
EPSG:3116: MAGNA-SIRGAS / Colombia Bogota zone
EPSG:3117: MAGNA-SIRGAS / Colombia East Central zone
EPSG:3118: MAGNA-SIRGAS / Colombia East zone
EPSG:21891: Bogota 1975 / Colombia West zone (obsoleto)
EPSG:21892: Bogota 1975 / Colombia Bogota zone (obsoleto)
EPSG:21893: Bogota 1975 / Colombia East Central zone (obsoleto)
EPSG:21894: Bogota 1975 / Colombia East (obsoleto)
EPSG:21896: Bogota 1975 / Colombia West zone
EPSG:21897: Bogota 1975 / Colombia Bogota zone
EPSG:21898: Bogota 1975 / Colombia East Central zone
EPSG:21899: Bogota 1975 / Colombia East
area
update set shape_area = area(transform(the_geom,21892))
update set shape_area = trunc(shape_area,2)
update set centro = st_askml(st_centroid(the_geom))
update set length = st_length(transform(the_geom,21892))

##################### ARECI #####################


shp2pgsql -s 4326 -I -W LATIN1 C:\a\simci\coca2007geo.shp coca2007> C:\a\areci\
coca2007.sql
ogr2ogr -f "ESRI Shapefile" mydata.shp PG:"host=myhost user=myloginname dbname=m
ydbname password=mypassword" -sql "SELECT name, the_geom FROM neighborhoods"
ogr2ogr -f "ESRI Shapefile" c:\a\popayan_urbano.shp PG:"host=localhost user=cauc
a dbname=geoscire password=123456" -sql "SELECT gid, objectid, ccde, ccmu, cczo,
ccse, ccmv, cter, pre_cod, shape_leng, shape_area, the_geom FROM popayan_urba
no"
ogr2ogr -f "ESRI Shapefile" c:\a\mun_borra.shp PG:"host=localhost user=cauca dbn
ame=geoscire password=123456" -sql "select d.nom_dpto, m.* from departamentos as
d, municipios as m where d.codane = m.codane_depto"
seleccionar estadistica
select m.depto, m.mun, m.centro,e.area_coca from municipios_estadistica as m, es
tadistica as e
where
m.id=e.id
and
e.ano='2006'
and
m.depto = 'AMAZONAS'
order by m.mun
$$$$ TRANSFORMAR DE PLANAS BOGOTA A GEOGRAFICAS WGS84
SELECT ST_X(transform(PointFromText('POINT(-76.1552100389186 1.09683261520326)',
4326),3116)), ST_X(transform(PointFromText('POINT(-76.3528563786913 3.1591886193
7051)',4326),3116))
-- transformacion de coordendas
SELECT ST_X(transform(PointFromText('POINT(943033 1081544)',21892),4326)) as w,
ST_Y(transform(PointFromText('POINT(943033 1081544)',21892),4326)) as n
juancho1703@hotmail.com
943033 , 1081544
943033 , 1081544
943033 , 1081544
943033 , 1081544
^^^^^^^^^^^^^^^^^^^^^^^convertir postgresql to ESRI Shapefile @@@@@@@@@@@@@@@@@@
@@@@@@@
ogr2ogr -f "ESRI Shapefile" c:\a\metales_preciosos.shp PG:"host=localhost user=c
auca dbname=geoscire password=123456" -sql "select * from metales_preciosos"
shp2pgsql -s 4326 -I -W LATIN1 C:\borra\cab_municipales_centroides.shp cab_munic
ipales_centroides> C:\borra\cab_municipales_centroides.sql
psql -d areci -f C:\borra\cab_municipales_centroides.sql -U areci
--intersectar un punto con la capa de municipios
select m.nom_mcipio, d.nom_dpto from municipios as m, departamentos as d
where
d.codane=m.codane_depto and
st_intersects(GeomFromText('POINT(-72.4676851888083 3.24700386207014)',4326), m.
the_geom);
--hallar la distancia entre dos puntos en geograficas
select ST_distance_sphere(ST_PointFromText('POINT(-76.2949713475893 1.1583910188
3955)',4326), ST_PointFromText('POINT(-76.4850651563726 3.28234250510886)',4326)
) as distancia_km
-- convertir dos puntos en azimut esta unidades esta dada en radianes
--
select ST_azimuth(ST_PointFromText('POINT(-76.2949713475893 1.15839101883955)',4
326), ST_PointFromText('POINT(-76.4850651563726 3.28234250510886)',4326)) as dis
tancia_km

$$$$$$$$$$$$$$$$^^^^^^^^^^^^^^^^^conectarse a postgresql $$$$$$$$$$$$$$$$$$$$$$$


$$$
psql -d nombre_de_database -U nombre_usuario
psql -d areci -U ramsanjo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
convertir postgresql to shapefile
pgsql2shp -f C:\a\borra1.shp -h localhost -u cauca -P 123456 -g the_geom areci f
ronteras

C:\Program Files\PostgreSQL\8.3\bin\pg_dump.exe -i -h localhost -p 5432 -U cauca


-F c -b -v -f "C:\a\borra.backup" "cauca"
$$$$$$$$$$$$$*())))))))))))))))))))))))) pagina web (((((((((((((((((
shp2pgsql -s 4326 -I -W LATIN1 C:\carpeta\archivo_shapefile.shp nombre_de_la_tab
la_en_la_base_de_datos> c:\rtuta\salida_sql.sql
psql -d nombre_base_datos -f C:\carpeta\archivo_sql.sql -U usuario
shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\areci_data\datos\resguardos_wgs84.sh
p resguardos> C:\a\resguardos.sql
psql -d areci -f C:\a\resguardos.sql -U areci
borrar una tabla con su referencia geometrica
select dropgeometrytable('public','resguardos_indigenas');
select nombre_del, grupo_etni, departamen, municipio, area__has_,poblacion, fami
lias from resguardos order by nombre_del
################
select * from tab_name order by column_name::integer;
select * from tab_name order by cast(column_name AS integer);
select * from tab_name order by int8 (column_name);
-- Table: estadistica_gral
-- DROP TABLE estadistica_gral;
CREATE TABLE estadistica_gral
(
codane numeric(10) NOT NULL,
area numeric(10),
operacion character varying(15),
ano character varying(4),
CONSTRAINT estadistica_gral_pkey PRIMARY KEY (codane)
)
WITH (OIDS=TRUE);
--consulta estadistica por departamento
select d.nom_dpto, sum(e.area) from departamentos as d, municipios as m, estadis
tica_gral as e
where
d.codane=m.codane_depto and m.codane=e.codane and e.operacion='ASPERSION' AND e.
ano='2007'
group by d.nom_dpto
order by d.nom_dpto

--
select d.nom_dpto, sum(e.area) from departamentos as d, municipios as m, estad
istica_gral as e
where
d.codane=m.codane_depto and m.codane=e.codane and e.operacion='ASPERSION' AND e.
ano='2007'
and e.area != 0
group by d.nom_dpto

-+++++++++++++++++++++++=============
select d.nom_dpto, sum(e.area) from departamentos as d, municipios as m, estad
istica_gral as e
where
d.codane=m.codane_depto and m.codane=e.codane and e.operacion='ASPERSION' AND e.
ano='2007'
group by d.nom_dpto
having sum(e.area) > 0
order by d.nom_dpto
##############################
CREATE INDEX codane_idx_est_gral
ON estadistica_gral
USING btree
(codane);
%%%%%%%%%%%%%%%%%%%%%%%
select sum(area) from estadistica_gral
where
ano='2002' and operacion = 'ASPERSION'
300 212 01 55
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Distancia vertimiento-centroide del municipio
En este ejemplo creamos una linea imaginaria entre el centroide del municipio y
cada vertimiento , para determinar aquellos que por definición hayan sido mal ingr
esados al sistema.
SELECT v.id_vertimiento, v.identif_vertimie, makeline(centroid(m.the_geom), v.th
e_geom) AS the_geom, length(makeline(centroid(m.the_geom), v.the_geom)) AS long
FROM dp_municipio m
LEFT JOIN ve_vertimiento v ON m.cod_municipio::text = v.cod_municipio::text
WHERE v.id_vertimiento IS NOT NULL;
Formas de espacialzar tablas:
cargar shep: shaepsql ogr2org se agregan a la tabla geometry_columns
funcion postGIS: SELECT AddGeometryColumn (...)
-> las dos formas crean el resgistro en la tabal geometry_colums
sist. de referecia espacial 21892 Cod
Solo cuando se crean vistas
/* correccion en la vista
SELECT v.oid AS gid, v.id_vertimiento, v.identif_vertimie, makeline(centroid(m.t
he_geom), v.the_geom) AS the_geom, length(makeline(centroid(m.the_geom), v.the_g
eom)) AS long
FROM dp_municipio m
LEFT JOIN ve_vertimiento v ON m.cod_municipio::text = v.cod_municipio::text
WHERE v.id_vertimiento IS NOT NULL;
cuando se creen las tablas, no usar espacion ni mayusculasn */
##################################################
consulta por municipios
select m.nom_mcipio, e.area from departamentos as d, municipios as m, estadistic
a_gral as e
where
d.codane=m.codane_depto and m.codane=e.codane and e.operacion='ASPERSION' AND e.
ano='2007' and d.nom_dpto='ANTIOQUIA'
and e.area > 0
order by m.nom_mcipio

^^^^^^^^^^^^^^^^^^^^
select m.nom_mcipio, e.area from departamentos as d, municipios as m, estadistic
a_gral as e
where
d.codane=m.codane_depto and m.codane=e.codane and e.operacion='EMANUAL' AND e.an
o='2007' and d.nom_dpto='ANTIOQUIA'
and e.area > 0
order by m.nom_mcipio

######$%^&*()_
dir > myfile.txt --- copiar los archivos a un directorios
c:\falcon view datos\CTLM50\CT50Z0A>dir > c:\borra\a.txt
gdal_translate -of GTiff -co "TILED=YES" C:\borra\C C:\borra\CT50Z0A_tif\0QXG
1013.tif

shp2pgsql -s 4326 -I -W LATIN1 C:\ms4w\apps\boyaca_data\datos\POTENCIALIDAD_MINE


RA_CENTROIDES.shp potencialidad_minera> C:\a\potencialidad_minera.sql
psql -d boyaca -f C:\boyaca\potencialidad_minera.sql -U boyaca
select DropGeometryTable('public', 'potencialidad_minera')
shp2pgsql -I -W LATIN1 c:\boyaca\POTENCIALIDAD_MINERA_CENTROIDES.shp potencialid
ad_minera > c:\boyaca\potencialidad_minera.sql

// generar un grupo de datos generallizando por un campo


SELECT layer, collect(the_geom) as the_geom FROM red_vial GROUP BY layer
pgsql2shp -f C:\borra\parques.shp -h localhost -u areci -P 123456 -g the_geom ar
eci "SELECT gid, nombre, hectares, the_geom FROM parques"
pgsql2shp -f C:\borra\cab_municipales.shp -h localhost -u areci -P 123456 -g the
_geom areci "SELECT gid, codane2, departamen, municipio, centro_pob, cod_dpto, c
od_mun, the_geom FROM cab_municipales"
|||||||||||||||||||||||||||||||||||||||||||||||||||||
select AddGeometryColumn('cab_municipales_punto','the_geom',4326,'POINT',2);
INSERT INTO cab_municipales_punto select codane2, departamen, municipio,centro_p
ob, cod_dpto, cod_mun, ST_Centroid(the_geom) from cab_municipales
SELECT st_extent(the_geom), xmin(st_extent(the_geom)) , ymin(st_extent(the_geom)
) ,
xmax(st_extent(the_geom)) , ymax(st_extent(the_geom))from table;
- Encuentra las geometrías que se sobrepone al punto POINT (-1 0).
SELECT id,nombre,the_geom FROM example_2_poligono WHERE the_geom && GeomFromText
('POINT(-1 0)', -1);
- Encuentra las geometrías que se sobrepone al box BOX3D(0 5,5 0).
SELECT id,nombre,the_geom FROM example_2_poligono WHERE the_geom && 'BOX3D(0 5,5
0)'::box3d;
select st_astext(st_buffer(st_transform(the_geom,32618),300)) from cab_municipal
es_punto
make newly added layers visible by default
psql -d areci -f c:\a\coca2000.sql -U areci
select d.codane, m.codane, m.nom_mcipio, c.areacoca from departamentos as d, mun
icipios as m, coca2001 as c
where
d.codane=m.codane_depto
and
m.codane=c.codane
and
d.nom_dpto='CAUCA'
select d.codane, m.codane, m.nom_mcipio, c.areacoca, st_askml(st_centroid((c.the
_geom))) from departamentos as d, municipios as m, coca2001 as c
where
d.codane=m.codane_depto
and
m.codane=c.codane
and
d.nom_dpto='NORTE DE SANTANDER'
//optimizacion de consultas
select departamentos.codane, municipios.codane, municipios.nom_mcipio, coca2001.
areacoca FROM departamentos LEFT JOIN (municipios JOIN coca2001 ON (municipios.
codane = coca2001.codane)) ON (departamentos.codane = municipios.codane_depto);
// texto mmonetary
SUM(c.areacoca)::text::money
SELECT * FROM radicadas LIMIT 10 OFFSET 10;
//
SELECT * FROM asignaciones INNER JOIN inventario ON asignaciones.serial = in
ventario.serial
// concatenar cadenas en postgresql
SELECT '-'|| asignaciones.serial ||'-' FROM asignaciones INNER JOIN inventari
o ON asignaciones.serial = inventario.serial
// tambien se puede expresar la primera sentencia de la siguiente manera
SELECT * FROM asignaciones, inventario where asignaciones.serial = inventario.
serial
// estado actual inventario
SELECT '-'||inventario.serial||'-' as serial, inventario.referencia, transferenc
ia, bodega, estado, fecha_ingreso, codigo_asesor, nro_asignacion, fecha_radica
FROM inventario LEFT OUTER JOIN asignaciones ON inventario.serial = asignacion
es.serial

You might also like