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 |
alfonx |
1251 |
import org.apache.log4j.Logger; |
17 |
alfonx |
1160 |
import org.geotools.data.DataAccess; |
18 |
|
|
import org.geotools.data.FeatureListener; |
19 |
|
|
import org.geotools.data.FeatureSource; |
20 |
|
|
import org.geotools.data.Query; |
21 |
|
|
import org.geotools.data.QueryCapabilities; |
22 |
|
|
import org.geotools.data.ResourceInfo; |
23 |
|
|
import org.geotools.feature.FeatureCollection; |
24 |
|
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
25 |
|
|
import org.opengis.feature.simple.SimpleFeature; |
26 |
|
|
import org.opengis.feature.simple.SimpleFeatureType; |
27 |
|
|
import org.opengis.feature.type.Name; |
28 |
|
|
import org.opengis.filter.Filter; |
29 |
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
30 |
|
|
import org.opengis.referencing.crs.GeographicCRS; |
31 |
|
|
|
32 |
alfonx |
1251 |
import schmitzm.geotools.feature.FeatureUtil; |
33 |
|
|
import schmitzm.lang.LangUtil; |
34 |
|
|
|
35 |
alfonx |
1160 |
import com.vividsolutions.jts.geom.Envelope; |
36 |
|
|
|
37 |
|
|
public class TwistedLatLonFeatureSource implements |
38 |
|
|
FeatureSource<SimpleFeatureType, SimpleFeature> { |
39 |
|
|
|
40 |
|
|
private final FeatureSource<SimpleFeatureType, SimpleFeature> originaleFS; |
41 |
|
|
private boolean twist = false; |
42 |
|
|
|
43 |
|
|
public TwistedLatLonFeatureSource( |
44 |
|
|
FeatureSource<SimpleFeatureType, SimpleFeature> originaleFS) { |
45 |
|
|
this.originaleFS = originaleFS; |
46 |
|
|
|
47 |
|
|
CoordinateReferenceSystem crs = originaleFS.getSchema() |
48 |
|
|
.getCoordinateReferenceSystem(); |
49 |
|
|
if (crs instanceof GeographicCRS) { |
50 |
alfonx |
1251 |
LOGGER.debug("CRS is GeographicCRS, twist it!"); |
51 |
alfonx |
1160 |
setTwist(true); |
52 |
|
|
} |
53 |
|
|
} |
54 |
|
|
|
55 |
alfonx |
1251 |
private static final Logger LOGGER = LangUtil |
56 |
|
|
.createLogger(TwistedLatLonFeatureSource.class); |
57 |
|
|
|
58 |
alfonx |
1160 |
@Override |
59 |
|
|
public void addFeatureListener(FeatureListener listener) { |
60 |
|
|
originaleFS.addFeatureListener(listener); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
@Override |
64 |
|
|
public ReferencedEnvelope getBounds() throws IOException { |
65 |
|
|
if (isTwist()) { |
66 |
|
|
Envelope oldEnv = originaleFS.getBounds(); |
67 |
|
|
return new ReferencedEnvelope(oldEnv.getMinY(), oldEnv.getMinX(), |
68 |
|
|
oldEnv.getMaxY(), oldEnv.getMaxX(), getSchema() |
69 |
|
|
.getCoordinateReferenceSystem()); |
70 |
|
|
} else |
71 |
|
|
return originaleFS.getBounds(); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
@Override |
75 |
|
|
public ReferencedEnvelope getBounds(Query query) throws IOException { |
76 |
|
|
return null; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
@Override |
80 |
|
|
public int getCount(Query query) throws IOException { |
81 |
|
|
return originaleFS.getCount(query); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
@Override |
85 |
|
|
public DataAccess<SimpleFeatureType, SimpleFeature> getDataStore() { |
86 |
|
|
return originaleFS.getDataStore(); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
@Override |
90 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures() |
91 |
|
|
throws IOException { |
92 |
|
|
return originaleFS.getFeatures(); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
@Override |
96 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures( |
97 |
|
|
Query query) throws IOException { |
98 |
|
|
return originaleFS.getFeatures(query); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
@Override |
102 |
|
|
public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures( |
103 |
|
|
Filter filter) throws IOException { |
104 |
|
|
return originaleFS.getFeatures(filter); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
@Override |
108 |
|
|
public QueryCapabilities getQueryCapabilities() { |
109 |
|
|
return originaleFS.getQueryCapabilities(); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
@Override |
113 |
|
|
public SimpleFeatureType getSchema() { |
114 |
|
|
return originaleFS.getSchema(); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
@Override |
118 |
|
|
public Set getSupportedHints() { |
119 |
|
|
return originaleFS.getSupportedHints(); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
@Override |
123 |
|
|
public void removeFeatureListener(FeatureListener listener) { |
124 |
|
|
originaleFS.removeFeatureListener(listener); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
@Override |
128 |
|
|
public ResourceInfo getInfo() { |
129 |
|
|
return originaleFS.getInfo(); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
@Override |
133 |
|
|
public Name getName() { |
134 |
|
|
return originaleFS.getName(); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
public void setTwist(boolean twist) { |
138 |
|
|
this.twist = twist; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
public boolean isTwist() { |
142 |
|
|
return twist; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
} |