# HG changeset patch # User Ingo Weinzierl # Date 1313679800 0 # Node ID e2deda3b77a7e6e94decb25f284d273335249946 # Parent 8b12b338a3f6d3d0a9a7d8f6e935796038cdc4f0 Introduced support for FLYS spatial data. flys-backend/trunk@2507 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu Aug 11 10:47:43 2011 +0000 +++ b/flys-backend/ChangeLog Thu Aug 18 15:03:20 2011 +0000 @@ -1,3 +1,26 @@ +2011-08-18 Ingo Weinzierl + + * doc/schema/postgresql-spatial.sql: The PostGIS database schema for + FLYS spatial data. + + * src/main/java/de/intevation/flys/model/CrossSectionTrack.java, + src/main/java/de/intevation/flys/model/RiverAxis.java, + src/main/java/de/intevation/flys/model/Line.java, + src/main/java/de/intevation/flys/model/Building.java, + src/main/java/de/intevation/flys/model/Fixpoint.java: Model classes that + represent FLYS spatial data. + + * src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java: + Registered model classes. + + * pom.xml: Added dependencies to HibernateSpatial and PostGIS. + + * src/main/java/de/intevation/flys/backend/SpatialInfo.java, + contrib/spatial-info.sh: A small demo application that prints out some + information about spatial data of specific rivers. Modify the system + property -Dflys.backend.spatial.river to get information of a river of + your choice. + 2011-07-31 Sascha L. Teichmann Re-enabled Hibernate schema dumps. diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/contrib/spatial-info.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/contrib/spatial-info.sh Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,10 @@ +#!/bin/bash + +mvn -e \ + -Dlog4j.configuration=file://`readlink -f contrib/log4j.properties` \ + -Dflys.backend.user=USER \ + -Dflys.backend.password=PASSWORD \ + -Dflys.backend.url=jdbc:postgresql://THE.DATABASE.HOST:PORT/DBNAME \ + -Dflys.backend.spatial.river=Saar \ + -Dexec.mainClass=de.intevation.flys.backend.SpatialInfo \ + exec:java diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/doc/schema/postgresql-spatial.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/doc/schema/postgresql-spatial.sql Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,50 @@ +BEGIN; + +CREATE TABLE river_axes ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + kind int NOT NULL DEFAULT 0 +); +SELECT AddGeometryColumn('river_axes', 'geom', 31466, 'LINESTRING', 2); + + +CREATE TABLE cross_section_tracks ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + km NUMERIC NOT NULL, + z NUMERIC NOT NULL DEFAULT 0 +); +SELECT AddGeometryColumn('cross_section_tracks', 'geom', 31466, 'LINESTRING', 2); + + +CREATE TABLE lines ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + kind int NOT NULL DEFAULT 0, + z NUMERIC DEFAULT 0 +); +SELECT AddGeometryColumn('lines', 'geom', 31466, 'LINESTRING', 4); +-- 'kind': +-- 0: ROHR1 +-- 1: DAMM + + +CREATE TABLE buildings ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + name VARCHAR(50) +); +SELECT AddGeometryColumn('buildings', 'geom', 31466, 'LINESTRING', 2); + + +CREATE TABLE fixpoints ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + x int, + y int, + km NUMERIC NOT NULL, + HPGP VARCHAR(2) +); +SELECT AddGeometryColumn('fixpoints', 'geom', 31466, 'POINT', 2); + +END; diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/pom.xml --- a/flys-backend/pom.xml Thu Aug 11 10:47:43 2011 +0000 +++ b/flys-backend/pom.xml Thu Aug 18 15:03:20 2011 +0000 @@ -78,6 +78,16 @@ 8.4-702.jdbc4 runtime + + org.hibernatespatial + hibernate-spatial-postgis + 1.1 + + + org.postgis + postgis-jdbc + 1.3.3 + @@ -86,5 +96,13 @@ JBoss Repository - Nexus http://repository.jboss.org/nexus/content/groups/public/ + + OSGEO GeoTools repo + http://download.osgeo.org/webdav/geotools + + + Hibernate Spatial repo + http://www.hibernatespatial.org/repository + diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java --- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Thu Aug 11 10:47:43 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Thu Aug 18 15:03:20 2011 +0000 @@ -12,24 +12,29 @@ import de.intevation.flys.model.Annotation; import de.intevation.flys.model.AnnotationType; import de.intevation.flys.model.Attribute; +import de.intevation.flys.model.Building; import de.intevation.flys.model.CrossSection; import de.intevation.flys.model.CrossSectionLine; import de.intevation.flys.model.CrossSectionPoint; +import de.intevation.flys.model.CrossSectionTrack; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.DischargeTableValue; import de.intevation.flys.model.Edge; +import de.intevation.flys.model.Fixpoint; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.HYK; import de.intevation.flys.model.HYKEntry; import de.intevation.flys.model.HYKFormation; import de.intevation.flys.model.HYKFlowZoneType; import de.intevation.flys.model.HYKFlowZone; +import de.intevation.flys.model.Line; import de.intevation.flys.model.MainValueType; import de.intevation.flys.model.NamedMainValue; import de.intevation.flys.model.MainValue; import de.intevation.flys.model.Position; import de.intevation.flys.model.Range; import de.intevation.flys.model.River; +import de.intevation.flys.model.RiverAxis; import de.intevation.flys.model.TimeInterval; import de.intevation.flys.model.WstColumn; import de.intevation.flys.model.WstColumnQRange; @@ -67,7 +72,8 @@ public static final String DEFAULT_DIALECT = System.getProperty( "flys.backend.dialect", - "org.hibernate.dialect.PostgreSQLDialect"); + //"org.hibernate.dialect.PostgreSQLDialect"); + "org.hibernatespatial.postgis.PostgisDialect"); public static final String DEFAULT_DRIVER = System.getProperty( @@ -147,24 +153,29 @@ cfg.addAnnotatedClass(Annotation.class); cfg.addAnnotatedClass(AnnotationType.class); cfg.addAnnotatedClass(Attribute.class); + cfg.addAnnotatedClass(Building.class); cfg.addAnnotatedClass(CrossSection.class); cfg.addAnnotatedClass(CrossSectionLine.class); cfg.addAnnotatedClass(CrossSectionPoint.class); + cfg.addAnnotatedClass(CrossSectionTrack.class); cfg.addAnnotatedClass(DischargeTable.class); cfg.addAnnotatedClass(DischargeTableValue.class); cfg.addAnnotatedClass(Edge.class); + cfg.addAnnotatedClass(Fixpoint.class); cfg.addAnnotatedClass(Gauge.class); cfg.addAnnotatedClass(HYK.class); cfg.addAnnotatedClass(HYKEntry.class); cfg.addAnnotatedClass(HYKFormation.class); cfg.addAnnotatedClass(HYKFlowZoneType.class); cfg.addAnnotatedClass(HYKFlowZone.class); + cfg.addAnnotatedClass(Line.class); cfg.addAnnotatedClass(MainValueType.class); cfg.addAnnotatedClass(NamedMainValue.class); cfg.addAnnotatedClass(MainValue.class); cfg.addAnnotatedClass(Position.class); cfg.addAnnotatedClass(Range.class); cfg.addAnnotatedClass(River.class); + cfg.addAnnotatedClass(RiverAxis.class); cfg.addAnnotatedClass(TimeInterval.class); cfg.addAnnotatedClass(WstColumn.class); cfg.addAnnotatedClass(WstColumnQRange.class); diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,180 @@ +package de.intevation.flys.backend; + +import java.util.List; + +import org.apache.log4j.Logger; + +import org.hibernate.Query; +import org.hibernate.Session; + +import com.vividsolutions.jts.geom.LineString; + +import de.intevation.flys.backend.SessionFactoryProvider; +import de.intevation.flys.model.Building; +import de.intevation.flys.model.CrossSectionTrack; +import de.intevation.flys.model.Fixpoint; +import de.intevation.flys.model.Line; +import de.intevation.flys.model.River; +import de.intevation.flys.model.RiverAxis; + + +public class SpatialInfo { + + private static Logger logger = Logger.getLogger(SpatialInfo.class); + + protected static String RIVERNAME = System.getProperty( + "flys.backend.spatial.river", "Saar"); + + protected Session session; + + + public static void main(String[] args) { + logger.info("Start SpatialInfo application."); + + SpatialInfo spatial = null; + + try { + spatial = new SpatialInfo(); + + River river = spatial.getRiver(RIVERNAME); + if (river == null) { + logger.warn("Could not find river '" + RIVERNAME + "'!"); + return; + } + + logger.info("Spatial information of River '" + RIVERNAME + "'"); + spatial.doRiverAxisInfo(river); + spatial.doCrossSectionTracksInfo(river); + spatial.doLinesInfo(river); + spatial.doBuildingsInfo(river); + spatial.doFixpointsInfo(river); + } + finally { + if (spatial != null) { + spatial.close(); + } + } + + logger.info("Finish SpatialInfo application."); + } + + + public SpatialInfo() { + session = SessionFactoryProvider + .createSessionFactory() + .openSession(); + } + + + public void close() { + session.close(); + } + + + protected River getRiver(String rivername) { + Query query = session.createQuery( + "from River where name =:name"); + query.setParameter("name", rivername); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No river '" + rivername + "' found!"); + return null; + } + + return list.get(0); + } + + + protected void doRiverAxisInfo(River river) { + Query query = session.createQuery( + "from RiverAxis where river =:river"); + query.setParameter("river", river); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No Riveraxis for '" + river.getName() + "' found!"); + return; + } + + RiverAxis axis = list.get(0); + if (axis != null) { + LineString ls = axis.getGeom(); + logger.info("River axis is " + ls.getLength() + " long."); + } + else { + logger.warn("River has no RiverAxis."); + } + } + + + protected void doCrossSectionTracksInfo(River river) { + Query query = session.createQuery( + "from CrossSectionTrack where river =:river"); + query.setParameter("river", river); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!"); + return; + } + else { + logger.info("River contains " + list.size() + " CrossSectionTracks."); + } + } + + + protected void doLinesInfo(River river) { + Query query = session.createQuery( + "from Line where river =:river"); + query.setParameter("river", river); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No Lines for '" + river.getName() + "' found!"); + return; + } + else { + logger.info("River contains " + list.size() + " Lines."); + } + } + + + protected void doBuildingsInfo(River river) { + Query query = session.createQuery( + "from Building where river =:river"); + query.setParameter("river", river); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No Buildings for '" + river.getName() + "' found!"); + return; + } + else { + logger.info("River contains " + list.size() + " Buildings."); + } + } + + + protected void doFixpointsInfo(River river) { + Query query = session.createQuery( + "from Fixpoint where river =:river"); + query.setParameter("river", river); + + List list = query.list(); + + if (list == null || list.size() == 0) { + logger.warn("No Fixpoints for '" + river.getName() + "' found!"); + return; + } + else { + logger.info("River contains " + list.size() + " Fixpoints."); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/model/Building.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Building.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,77 @@ +package de.intevation.flys.model; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import com.vividsolutions.jts.geom.LineString; + + +@Entity +@Table(name = "buildings") +public class Building +implements Serializable +{ + private Integer id; + private River river; + private String name; + private LineString geom; + + public Building() { + } + + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + + public void setId(Integer id) { + this.id = id; + } + + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + + public void setRiver(River river) { + this.river = river; + } + + + @Column(name = "name") + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + @Column(name = "geom") + @Type(type = "org.hibernatespatial.GeometryUserType") + public LineString getGeom() { + return geom; + } + + + public void setGeom(LineString geom) { + this.geom = geom; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,90 @@ +package de.intevation.flys.model; + +import java.io.Serializable; +import java.math.BigDecimal; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import com.vividsolutions.jts.geom.LineString; + + +@Entity +@Table(name = "cross_section_tracks") +public class CrossSectionTrack +implements Serializable +{ + private Integer id; + private River river; + private LineString geom; + private BigDecimal km; + private BigDecimal z; + + public CrossSectionTrack() { + } + + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + + public void setId(Integer id) { + this.id = id; + } + + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + + public void setRiver(River river) { + this.river = river; + } + + + @Column(name = "geom") + @Type(type = "org.hibernatespatial.GeometryUserType") + public LineString getGeom() { + return geom; + } + + + public void setGeom(LineString geom) { + this.geom = geom; + } + + + @Column(name = "km") + public BigDecimal getKm() { + return km; + } + + + public void setKm(BigDecimal km) { + this.km = km; + } + + + @Column(name = "z") + public BigDecimal getZ() { + return z; + } + + + public void setZ(BigDecimal z) { + this.z = z; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/model/Fixpoint.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Fixpoint.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,114 @@ +package de.intevation.flys.model; + +import java.io.Serializable; +import java.math.BigDecimal; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import com.vividsolutions.jts.geom.Point; + + +@Entity +@Table(name = "fixpoints") +public class Fixpoint +implements Serializable +{ + private Integer id; + private River river; + private Integer x; + private Integer y; + private BigDecimal km; + private String hpgp; + private Point geom; + + public Fixpoint() { + } + + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + + public void setId(Integer id) { + this.id = id; + } + + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + + public void setRiver(River river) { + this.river = river; + } + + + @Column(name = "x") + public Integer getX() { + return x; + } + + + public void setX(Integer x) { + this.x = x; + } + + + @Column(name = "y") + public Integer getY() { + return y; + } + + + public void setY(Integer y) { + this.y = y; + } + + + @Column(name = "km") + public BigDecimal getKm() { + return km; + } + + + public void setKm(BigDecimal km) { + this.km = km; + } + + + @Column(name = "hpgp") + public String getHpgp() { + return hpgp; + } + + + public void setHpgp(String hpgp) { + this.hpgp = hpgp; + } + + + @Column(name = "geom") + @Type(type = "org.hibernatespatial.GeometryUserType") + public Point getGeom() { + return geom; + } + + + public void setGeom(Point geom) { + this.geom = geom; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/model/Line.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Line.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,90 @@ +package de.intevation.flys.model; + +import java.io.Serializable; +import java.math.BigDecimal; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import com.vividsolutions.jts.geom.LineString; + + +@Entity +@Table(name = "lines") +public class Line +implements Serializable +{ + private Integer id; + private Integer kind; + private River river; + private LineString geom; + private BigDecimal z; + + public Line() { + } + + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + + public void setId(Integer id) { + this.id = id; + } + + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + + public void setRiver(River river) { + this.river = river; + } + + + @Column(name = "kind") + public Integer getKind() { + return kind; + } + + + public void setKind(Integer kind) { + this.kind = kind; + } + + + @Column(name = "geom") + @Type(type = "org.hibernatespatial.GeometryUserType") + public LineString getGeom() { + return geom; + } + + + public void setGeom(LineString geom) { + this.geom = geom; + } + + + @Column(name = "z") + public BigDecimal getZ() { + return z; + } + + + public void setZ(BigDecimal z) { + this.z = z; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8b12b338a3f6 -r e2deda3b77a7 flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java Thu Aug 18 15:03:20 2011 +0000 @@ -0,0 +1,77 @@ +package de.intevation.flys.model; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import com.vividsolutions.jts.geom.LineString; + + +@Entity +@Table(name = "river_axes") +public class RiverAxis +implements Serializable +{ + private Integer id; + private Integer kind; + private River river; + private LineString geom; + + public RiverAxis() { + } + + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + + public void setId(Integer id) { + this.id = id; + } + + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + + public void setRiver(River river) { + this.river = river; + } + + + @Column(name = "kind") + public Integer getKind() { + return kind; + } + + + public void setKind(Integer kind) { + this.kind = kind; + } + + + @Column(name = "geom") + @Type(type = "org.hibernatespatial.GeometryUserType") + public LineString getGeom() { + return geom; + } + + + public void setGeom(LineString geom) { + this.geom = geom; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :