Mercurial > dive4elements > gnv-client
comparison geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/GroupBySample.java @ 377:6a585e87c18b
Added RegionFilter-Support to HorizontalProfile InstantaneousPoint
geo-backend/trunk@377 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 27 Nov 2009 12:59:04 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
279:3c38ef20d622 | 377:6a585e87c18b |
---|---|
1 package de.intevation.gnv.geobackend.base.query; | |
2 | |
3 import com.esri.sde.sdk.client.SDEPoint; | |
4 import com.esri.sde.sdk.client.SeColumnDefinition; | |
5 import com.esri.sde.sdk.client.SeConnection; | |
6 import com.esri.sde.sdk.client.SeException; | |
7 import com.esri.sde.sdk.client.SeFilter; | |
8 import com.esri.sde.sdk.client.SeLayer; | |
9 import com.esri.sde.sdk.client.SeQuery; | |
10 import com.esri.sde.sdk.client.SeQueryInfo; | |
11 import com.esri.sde.sdk.client.SeRow; | |
12 import com.esri.sde.sdk.client.SeShape; | |
13 import com.esri.sde.sdk.client.SeShapeFilter; | |
14 import com.esri.sde.sdk.client.SeSqlConstruct; | |
15 | |
16 public class GroupBySample { | |
17 | |
18 | |
19 public void executeQuery(SeConnection con, String[] pLayername, | |
20 String pSpatialColumnName, String pWhere, | |
21 SDEPoint[] g, String[] pReturnFields, String byClause) { | |
22 | |
23 try { | |
24 // get the layer for querying | |
25 | |
26 SeShapeFilter[] filters = null; | |
27 if (g != null){ | |
28 SeLayer lLayer = new SeLayer(con, pLayername[0], pSpatialColumnName); | |
29 SeShape shape = new SeShape(); | |
30 shape.setCoordRef(lLayer.getCoordRef()); | |
31 | |
32 | |
33 | |
34 shape.generatePolygon(g.length, 1, null, g); | |
35 SeShapeFilter filter = new SeShapeFilter(pLayername[0], | |
36 pSpatialColumnName, shape, SeFilter.METHOD_AI); | |
37 filters = new SeShapeFilter[1]; | |
38 filters[0] = filter; | |
39 } | |
40 | |
41 SeQuery spatialQuery = null; | |
42 SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername, pWhere); | |
43 spatialQuery = new SeQuery(con); | |
44 | |
45 SeQueryInfo queryInfo = new SeQueryInfo(); | |
46 queryInfo.setColumns(pReturnFields); | |
47 | |
48 if (byClause != null){ | |
49 queryInfo.setByClause(byClause); | |
50 } | |
51 | |
52 queryInfo.setConstruct(sqlCons); | |
53 spatialQuery.prepareQueryInfo(queryInfo); | |
54 | |
55 /* | |
56 * Set spatial constraints | |
57 */ | |
58 if (filters != null){ | |
59 spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, | |
60 filters); | |
61 } | |
62 spatialQuery.execute(); | |
63 | |
64 SeRow row; | |
65 int lCount; | |
66 for (lCount = 0; (row =spatialQuery.fetch()) != null; lCount++) { | |
67 // one time execution | |
68 if (lCount == 0) { | |
69 // analyze cols of result set | |
70 SeColumnDefinition[] lCols = row.getColumns(); | |
71 | |
72 } | |
73 short lNumCols = row.getNumColumns(); | |
74 | |
75 for (int i = 0; i < lNumCols; i++) { | |
76 System.out.println(row.getObject(i)); | |
77 } | |
78 | |
79 } | |
80 spatialQuery.close(); | |
81 | |
82 } catch (Exception e){ | |
83 e.printStackTrace(); | |
84 } | |
85 | |
86 } | |
87 | |
88 | |
89 /** | |
90 * @param args | |
91 */ | |
92 public static void main(String[] args) { | |
93 | |
94 try { | |
95 String[] layerNames = new String[] { "median.meshpoint", "median.mesh" }; | |
96 String spatialColumnName = "SHAPE"; | |
97 String where = "median.meshpoint.meshid = median.mesh.meshid"; | |
98 String[] returnFields = new String[] { "sourceid" }; | |
99 String byClause = "group by sourceid"; | |
100 SDEPoint[] g = new SDEPoint[4]; | |
101 g[0] = new SDEPoint(52, 8); | |
102 g[1] = new SDEPoint(52, 9); | |
103 g[2] = new SDEPoint(53, 9); | |
104 g[3] = new SDEPoint(53, 8); | |
105 | |
106 String server = ""; | |
107 String port = ""; | |
108 String database = ""; | |
109 String username = ""; | |
110 String credentials = ""; | |
111 SeConnection con = new SeConnection(server, port, | |
112 database, username, | |
113 credentials); | |
114 new GroupBySample().executeQuery(con, layerNames, spatialColumnName, | |
115 where, g, returnFields, byClause); | |
116 | |
117 | |
118 } catch (SeException e) { | |
119 e.printStackTrace(); | |
120 } | |
121 } | |
122 } |