1 |
alfonx |
1160 |
/******************************************************************************* |
2 |
|
|
* Copyright (c) 2010 Stefan A. Tzeggai. |
3 |
|
|
* All rights reserved. This program and the accompanying materials |
4 |
|
|
* are made available under the terms of the GNU Public License v2.0 |
5 |
|
|
* which accompanies this distribution, and is available at |
6 |
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
7 |
|
|
* |
8 |
|
|
* Contributors: |
9 |
|
|
* Stefan A. Tzeggai - initial API and implementation |
10 |
|
|
******************************************************************************/ |
11 |
|
|
package skrueger.geotools.io; |
12 |
|
|
|
13 |
|
|
import java.io.IOException; |
14 |
|
|
import java.util.Set; |
15 |
|
|
|
16 |
|
|
import org.geotools.data.DataAccess; |
17 |
|
|
import org.geotools.data.FeatureListener; |
18 |
|
|
import org.geotools.data.FeatureSource; |
19 |
|
|
import org.geotools.data.Query; |
20 |
|
|
import org.geotools.data.QueryCapabilities; |
21 |
|
|
import org.geotools.data.ResourceInfo; |
22 |
|
|
import org.geotools.feature.FeatureCollection; |
23 |
|
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
24 |
|
|
import org.opengis.feature.simple.SimpleFeature; |
25 |
|
|
import org.opengis.feature.simple.SimpleFeatureType; |
26 |
|
|
import org.opengis.feature.type.Name; |
27 |
|
|
import org.opengis.filter.Filter; |
28 |
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
29 |
|
|
import org.opengis.referencing.crs.GeographicCRS; |
30 |
|
|
|
31 |
|
|
import com.vividsolutions.jts.geom.Envelope; |
32 |
|
|
|
33 |
|
|
public class TwistedLatLonFeatureSource implements |
34 |
|
|
FeatureSource<SimpleFeatureType, SimpleFeature> { |
35 |
|
|
|
36 |
|
|
private final FeatureSource<SimpleFeatureType, SimpleFeature> originaleFS; |
37 |
|
|
private boolean twist = false; |
38 |
|
|
|
39 |
|
|
public TwistedLatLonFeatureSource( |
40 |
|
|
FeatureSource<SimpleFeatureType, SimpleFeature> originaleFS) { |
41 |
|
|
this.originaleFS = originaleFS; |
42 |
|
|
|
43 |
|
|
CoordinateReferenceSystem crs = originaleFS.getSchema() |
44 |
|
|
.getCoordinateReferenceSystem(); |
45 |
|
|
if (crs instanceof GeographicCRS) { |
46 |
|
|
System.out.println("CRS is GeographicCRS, twist it!"); |
47 |
|
|
setTwist(true); |
48 |
|
|
} |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
@Override |
52 |
|
|
public void addFeatureListener(FeatureListener listener) { |
53 |
|
|
originaleFS.addFeatureListener(listener); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
@Override |
57 |
|
|
public ReferencedEnvelope getBounds() throws IOException { |
58 |
|
|
if (isTwist()) { |
59 |
|
|
Envelope oldEnv = originaleFS.getBounds(); |
60 |
|
|
return new ReferencedEnvelope(oldEnv.getMinY(), oldEnv.getMinX(), |
61 |
|
|
oldEnv.getMaxY(), oldEnv.getMaxX(), getSchema() |
62 |
|
|
.getCoordinateReferenceSystem()); |
63 |
|
|
} else |
64 |
|
|
return originaleFS.getBounds(); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
@Override |
68 |
|
|
public ReferencedEnvelope getBounds(Query query) throws IOException { |
69 |
|
|
return null; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
@Override |
73 |
|
|
public int getCount(Query query) throws IOException { |
74 |
|
|
return originaleFS.getCount(query); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
@Override |
78 |
|
|
public DataAccess<SimpleFeatureType, SimpleFeature> getDataStore() { |
79 |
|
|
return originaleFS.getDataStore(); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
@Override |
83 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures() |
84 |
|
|
throws IOException { |
85 |
|
|
return originaleFS.getFeatures(); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
@Override |
89 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures( |
90 |
|
|
Query query) throws IOException { |
91 |
|
|
return originaleFS.getFeatures(query); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
@Override |
95 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures( |
96 |
|
|
Filter filter) throws IOException { |
97 |
|
|
return originaleFS.getFeatures(filter); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
@Override |
101 |
|
|
public QueryCapabilities getQueryCapabilities() { |
102 |
|
|
return originaleFS.getQueryCapabilities(); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
@Override |
106 |
|
|
public SimpleFeatureType getSchema() { |
107 |
|
|
return originaleFS.getSchema(); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
@Override |
111 |
|
|
public Set getSupportedHints() { |
112 |
|
|
return originaleFS.getSupportedHints(); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
@Override |
116 |
|
|
public void removeFeatureListener(FeatureListener listener) { |
117 |
|
|
originaleFS.removeFeatureListener(listener); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
@Override |
121 |
|
|
public ResourceInfo getInfo() { |
122 |
|
|
return originaleFS.getInfo(); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
@Override |
126 |
|
|
public Name getName() { |
127 |
|
|
return originaleFS.getName(); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
public void setTwist(boolean twist) { |
131 |
|
|
this.twist = twist; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
public boolean isTwist() { |
135 |
|
|
return twist; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
} |