refactor: 불필요한 WMS기능 제거
parent
47055cc170
commit
1d1636198e
2
list.txt
2
list.txt
|
|
@ -1,4 +1,4 @@
|
|||
#src\main\resources\egovframework\egovProps\globals.properties
|
||||
src\main\resources\egovframework\egovProps\globals.properties
|
||||
#src\main\java\geoinfo\regi\manageList\ManageExcelUploadProc01Controller.java
|
||||
#src\main\webapp\WEB-INF\views\web\input\excel_step00.jsp
|
||||
#src\main\webapp\WEB-INF\views\web\input\excel_step31.jsp
|
||||
|
|
|
|||
104
pom.xml
104
pom.xml
|
|
@ -24,6 +24,8 @@
|
|||
<spring.maven.artifact.version>4.0.9.RELEASE</spring.maven.artifact.version>
|
||||
<egovframework.rte.version>3.5.0</egovframework.rte.version>
|
||||
|
||||
<geotools.version>11.0</geotools.version>
|
||||
<jts.version>1.13</jts.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
|
@ -487,113 +489,125 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-main</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-main</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-opengis</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-opengis</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-referencing</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-referencing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-epsg-hsql</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-epsg-hsql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-cql</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-cql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-data</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-data</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-api</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-api</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-metadata</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-metadata</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-xml</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-xml</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-swing</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-swing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-render</artifactId>
|
||||
<version>11.0</version>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-render</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-shapefile</artifactId>
|
||||
<version>11.0</version>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.xsd</groupId>
|
||||
<artifactId>gt-xsd-sld</artifactId>
|
||||
<version>11.0</version>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-geojson</artifactId>
|
||||
<version>11.0</version>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-process</artifactId>
|
||||
<version>11.0</version>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-jdbc</artifactId>
|
||||
<version>11.0</version>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-postgis</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-postgis</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-oracle</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-oracle</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-h2</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-h2</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-mysql</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-mysql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-db2</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-db2</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-sqlserver</artifactId> <version>11.0</version>
|
||||
<artifactId>gt-jdbc-sqlserver</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vividsolutions</groupId>
|
||||
<artifactId>jts</artifactId>
|
||||
<version>1.13</version>
|
||||
<version>${jts.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-wms</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.xsd/org.eclipse.xsd -->
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import javax.annotation.Resource;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
import org.osgeo.proj4j.CRSFactory;
|
||||
import org.osgeo.proj4j.CoordinateReferenceSystem;
|
||||
import org.osgeo.proj4j.CoordinateTransform;
|
||||
|
|
@ -27,8 +26,6 @@ import com.jhlabs.map.proj.Projection;
|
|||
import com.jhlabs.map.proj.ProjectionFactory;
|
||||
|
||||
import egovframework.com.cmm.service.EgovProperties;
|
||||
import egovframework.com.json.JSONArray;
|
||||
import egovframework.com.json.JSONObject;
|
||||
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||
import geoinfo.com.GeoinfoCommon;
|
||||
import geoinfo.map.coordSearch.service.MapCoordSearchService;
|
||||
|
|
|
|||
|
|
@ -30,12 +30,6 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jfree.util.Log;
|
||||
import org.osgeo.proj4j.CRSFactory;
|
||||
import org.osgeo.proj4j.CoordinateReferenceSystem;
|
||||
import org.osgeo.proj4j.CoordinateTransform;
|
||||
import org.osgeo.proj4j.CoordinateTransformFactory;
|
||||
import org.osgeo.proj4j.Proj4jException;
|
||||
import org.osgeo.proj4j.ProjCoordinate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
|
|||
|
|
@ -1,304 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class AVList {
|
||||
private HashMap<String, Object> avList;
|
||||
|
||||
public AVList()
|
||||
{
|
||||
this.avList = new HashMap();
|
||||
}
|
||||
|
||||
public synchronized Object getValue(String key)
|
||||
{
|
||||
if ((key == null) || (key.trim().equals("")))
|
||||
{
|
||||
throw new IllegalArgumentException("AVList :: Key is NULL.");
|
||||
}
|
||||
|
||||
return this.avList.get(key);
|
||||
}
|
||||
|
||||
public synchronized Collection<Object> getValues()
|
||||
{
|
||||
return this.avList.values();
|
||||
}
|
||||
|
||||
public synchronized Set<Map.Entry<String, Object>> getEntries()
|
||||
{
|
||||
return this.avList.entrySet();
|
||||
}
|
||||
|
||||
public synchronized Object setValue(String key, Object value)
|
||||
{
|
||||
if ((key == null) || (key.trim().equals("")))
|
||||
{
|
||||
throw new IllegalArgumentException("AVList :: Key is NULL.");
|
||||
}
|
||||
|
||||
return this.avList.put(key, value);
|
||||
}
|
||||
|
||||
public synchronized AVList setValues(AVList list)
|
||||
{
|
||||
if (list == null)
|
||||
{
|
||||
throw new IllegalArgumentException("AVList :: AVList is NULL.");
|
||||
}
|
||||
|
||||
Set<Entry<String, Object>> entries = list.getEntries();
|
||||
for (Entry entry : entries)
|
||||
{
|
||||
setValue((String)entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized boolean hasKey(String key)
|
||||
{
|
||||
if ((key == null) || (key.trim().equals("")))
|
||||
{
|
||||
throw new IllegalArgumentException("AVList :: Key is NULL.");
|
||||
}
|
||||
|
||||
return this.avList.containsKey(key);
|
||||
}
|
||||
|
||||
public synchronized Object removeKey(String key)
|
||||
{
|
||||
if ((key == null) || (key.trim().equals("")))
|
||||
{
|
||||
throw new IllegalArgumentException("AVList :: Key is NULL.");
|
||||
}
|
||||
|
||||
return hasKey(key) ? this.avList.remove(key) : null;
|
||||
}
|
||||
|
||||
public synchronized AVList copy()
|
||||
{
|
||||
AVList clone = new AVList();
|
||||
|
||||
if (this.avList != null)
|
||||
{
|
||||
clone.avList.putAll(this.avList);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public synchronized AVList clearList()
|
||||
{
|
||||
this.avList.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized String getStringValue(String key, String defaultValue)
|
||||
{
|
||||
String v = getStringValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized String getStringValue(String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getValue(key).toString(); } catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Integer getIntegerValue(String key, Integer defaultValue)
|
||||
{
|
||||
Integer v = getIntegerValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized Integer getIntegerValue(String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Integer)) {
|
||||
return (Integer)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
Double d = Double.valueOf(Double.parseDouble(v));
|
||||
return Integer.valueOf(d.intValue());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Long getLongValue(String key, Long defaultValue)
|
||||
{
|
||||
Long v = getLongValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized Long getLongValue(String key)
|
||||
{
|
||||
try {
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Long)) {
|
||||
return (Long)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
Double d = Double.valueOf(Double.parseDouble(v));
|
||||
return Long.valueOf(d.longValue());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}return null;
|
||||
}
|
||||
|
||||
public synchronized Double getDoubleValue(String key, Double defaultValue)
|
||||
{
|
||||
Double v = getDoubleValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized Double getDoubleValue(String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Double)) {
|
||||
return (Double)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
return Double.valueOf(Double.parseDouble(v));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Boolean getBooleanValue(String key, Boolean defaultValue)
|
||||
{
|
||||
Boolean v = getBooleanValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized Boolean getBooleanValue(String key)
|
||||
{
|
||||
try {
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Boolean)) {
|
||||
return (Boolean)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
return Boolean.valueOf(Boolean.parseBoolean(v));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Date getDateValue(String key, Date defaultValue)
|
||||
{
|
||||
Date v = getDateValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
|
||||
public synchronized Date getDateValue(String key) {
|
||||
try {
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Date)) {
|
||||
return (Date)o;
|
||||
}
|
||||
Long v = getLongValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
return new Date(v.longValue());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized URL getURLValue(String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof URL)) {
|
||||
return (URL)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
if (v.length() != v.lastIndexOf("/") + 1) {
|
||||
v = v.concat("/");
|
||||
}
|
||||
|
||||
return new URL(v);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Color getColorValue(String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object o = getValue(key);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
if ((o instanceof Color)) {
|
||||
return (Color)o;
|
||||
}
|
||||
String v = getStringValue(key);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
return Color.decode(v);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized Color getColorValue(String key, Color defaultValue)
|
||||
{
|
||||
Color v = getColorValue(key);
|
||||
return v != null ? v : defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,507 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
|
||||
public class AWTLabelUtil {
|
||||
public static Point2D getLabelPositionMBR(LabelInfo labelInfo) {
|
||||
Point2D mbrPoint = AWTLabelUtil.getCrossLineCenter(labelInfo.generalPath, new Point2D.Double(labelInfo.generalPath.getBounds().getCenterX(), labelInfo.generalPath.getBounds().getCenterY()));
|
||||
if (mbrPoint == null) {
|
||||
return new Point2D.Double(labelInfo.polygon.getCentroid().getX(), labelInfo.polygon.getCentroid().getY());
|
||||
}
|
||||
return mbrPoint;
|
||||
}
|
||||
|
||||
public static Point2D getLabelPosition(LabelInfo labelInfo, Point2D point) {
|
||||
Point2D labelPoint = AWTLabelUtil.getCrossLineCenter(labelInfo.generalPath, new Point2D.Double(point.getX(), point.getY()));
|
||||
if (labelPoint == null) {
|
||||
return point;
|
||||
}
|
||||
return labelPoint;
|
||||
}
|
||||
|
||||
public static boolean isContainLabel(LabelInfo labelInfo, Point2D center, double rotation) {
|
||||
AffineTransform transform = AWTLabelUtil.getPolygonAlignTextTransform(labelInfo, center, rotation);
|
||||
Rectangle2D labelBound = labelInfo.labelPainter.getFullLabelBounds();
|
||||
Point2D.Double UL = new Point2D.Double(labelBound.getMinX(), labelBound.getMinY());
|
||||
Point2D.Double UR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMinY());
|
||||
Point2D.Double LL = new Point2D.Double(labelBound.getMinX(), labelBound.getMaxY());
|
||||
Point2D.Double LR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMaxY());
|
||||
transform.transform(UL, UL);
|
||||
transform.transform(UR, UR);
|
||||
transform.transform(LL, LL);
|
||||
transform.transform(LR, LR);
|
||||
if (!labelInfo.generalPath.contains(UL)) {
|
||||
return false;
|
||||
}
|
||||
if (!labelInfo.generalPath.contains(UR)) {
|
||||
return false;
|
||||
}
|
||||
if (!labelInfo.generalPath.contains(LL)) {
|
||||
return false;
|
||||
}
|
||||
return labelInfo.generalPath.contains(LR);
|
||||
}
|
||||
|
||||
public static boolean isContainLabel(LabelInfo labelInfo, AffineTransform transform) {
|
||||
Rectangle2D labelBound = labelInfo.labelPainter.getFullLabelBounds();
|
||||
Point2D.Double UL = new Point2D.Double(labelBound.getMinX(), labelBound.getMinY());
|
||||
Point2D.Double UR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMinY());
|
||||
Point2D.Double LL = new Point2D.Double(labelBound.getMinX(), labelBound.getMaxY());
|
||||
Point2D.Double LR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMaxY());
|
||||
transform.transform(UL, UL);
|
||||
transform.transform(UR, UR);
|
||||
transform.transform(LL, LL);
|
||||
transform.transform(LR, LR);
|
||||
if (!labelInfo.generalPath.contains(UL)) {
|
||||
return false;
|
||||
}
|
||||
if (!labelInfo.generalPath.contains(UR)) {
|
||||
return false;
|
||||
}
|
||||
if (!labelInfo.generalPath.contains(LL)) {
|
||||
return false;
|
||||
}
|
||||
return labelInfo.generalPath.contains(LR);
|
||||
}
|
||||
|
||||
public static boolean refineLabelPositionQuadrant(LabelInfo labelInfo, double rotation) {
|
||||
double rectX = labelInfo.generalPath.getBounds2D().getX();
|
||||
double rectY = labelInfo.generalPath.getBounds2D().getY();
|
||||
double width = labelInfo.generalPath.getBounds2D().getWidth() / 4.0;
|
||||
double height = labelInfo.generalPath.getBounds2D().getHeight() / 4.0;
|
||||
Point2D[] rePoints = new Point2D[]{new Point2D.Double(rectX + width, rectY + height), new Point2D.Double(rectX + width * 3.0, rectY + height), new Point2D.Double(rectX + width, rectY + height * 3.0), new Point2D.Double(rectX + width * 3.0, rectY + height * 3.0)};
|
||||
int i = 0;
|
||||
while (i < 4) {
|
||||
rePoints[i] = AWTLabelUtil.getLabelPosition(labelInfo, rePoints[i]);
|
||||
if (AWTLabelUtil.isContainLabel(labelInfo, rePoints[i], rotation)) {
|
||||
labelInfo.center = rePoints[i];
|
||||
return true;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static AffineTransform getPolygonAlignTextTransform(LabelInfo labelInfo, Point2D center, double rotation) {
|
||||
AffineTransform transform = new AffineTransform();
|
||||
transform.translate(center.getX(), center.getY());
|
||||
if (Double.isNaN(rotation) || Double.isInfinite(rotation)) {
|
||||
rotation = 0.0;
|
||||
}
|
||||
transform.rotate(rotation);
|
||||
Rectangle2D textBounds = labelInfo.labelPainter.getLabelBounds();
|
||||
double displacementX = labelInfo.anchorX * -textBounds.getWidth() + labelInfo.displacementX;
|
||||
double displacementY = labelInfo.anchorY * textBounds.getHeight() - labelInfo.displacementY - textBounds.getHeight() + labelInfo.labelPainter.getLineHeight();
|
||||
transform.translate(displacementX, displacementY);
|
||||
return transform;
|
||||
}
|
||||
|
||||
public static void setLabelRotationORTHO(LabelInfo labelInfo) {
|
||||
Vector<Point2D> hPoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, 0.0);
|
||||
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, 1.5707963267948966);
|
||||
Line2D hLine = AWTLabelUtil.getIntersectLineH(hPoints, labelInfo.center);
|
||||
Line2D vLine = AWTLabelUtil.getIntersectLineV(vPoints, labelInfo.center);
|
||||
if (hLine.getBounds().getWidth() > vLine.getBounds().getHeight()) {
|
||||
labelInfo.rCenter = labelInfo.center;
|
||||
labelInfo.rotation = 0.0;
|
||||
} else {
|
||||
labelInfo.rCenter = new Point2D.Double(vLine.getX1(), (vLine.getY1() + vLine.getY2()) / 2.0);
|
||||
labelInfo.rotation = -1.5707963267948966;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLabelRotationMBR(LabelInfo labelInfo) {
|
||||
labelInfo.rotation = Math.toRadians(AWTLabelUtil.calcMainAngle(labelInfo.generalPath));
|
||||
KLISLabelUtil pUtil = new KLISLabelUtil(labelInfo.polygon);
|
||||
if (pUtil.isConvex()) {
|
||||
labelInfo.rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||
} else {
|
||||
Point2D rCenter = pUtil.GetMIC_ex();
|
||||
if (rCenter == null) {
|
||||
labelInfo.rCenter = AWTLabelUtil.getOptimalCenter(labelInfo.generalPath, labelInfo.center);
|
||||
} else if (pUtil.hasParabola() == 0) {
|
||||
labelInfo.rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||
} else {
|
||||
Vector<Point2D> points = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||
double dist = Point2D.distance(points.get(0).getX(), points.get(0).getY(), points.get(1).getX(), points.get(1).getY());
|
||||
if (pUtil.getMaxRadius() * 10.0 < dist && pUtil.getMaxRadius() > labelInfo.labelPainter.getFullLabelBounds().getHeight() * 5.0) {
|
||||
labelInfo.rCenter = AWTLabelUtil.getOptimalCenter(labelInfo.generalPath, labelInfo.center);
|
||||
} else {
|
||||
Vector<Point2D> rpoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, labelInfo.rotation + 1.5707963267948966);
|
||||
Vector<Point2D> rpoints_v = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, rCenter, labelInfo.rotation + 1.5707963267948966);
|
||||
Vector<Point2D> rpoints_h = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, rCenter, labelInfo.rotation);
|
||||
if (rpoints_v.size() == 2 && rpoints.size() == 2 && rpoints_h.size() == 2) {
|
||||
double diff;
|
||||
double dist0 = Point2D.distance(rpoints.get(0).getX(), rpoints.get(0).getY(), rpoints.get(1).getX(), rpoints.get(1).getY());
|
||||
double dist_v = Point2D.distance(rpoints_v.get(0).getX(), rpoints_v.get(0).getY(), rpoints_v.get(1).getX(), rpoints_v.get(1).getY());
|
||||
double dist_h = Point2D.distance(rpoints_h.get(0).getX(), rpoints_h.get(0).getY(), rpoints_h.get(1).getX(), rpoints_h.get(1).getY());
|
||||
double d = diff = dist0 >= dist_v ? dist_v / dist0 : dist0 / dist_v;
|
||||
if (diff > 0.8 && dist_v * 5.0 < dist_h && pUtil.edgeDiffCounts() % 2 != 1) {
|
||||
rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||
}
|
||||
}
|
||||
labelInfo.rCenter = rCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Point2D getConvexCenter(GeneralPath generalPath, Point2D center, double rotation) {
|
||||
Vector<Point2D> points = AWTLabelUtil.getIntersectPoints(generalPath, center, rotation);
|
||||
Line2D line = AWTLabelUtil.getIntersectLineHV(points, center);
|
||||
if (line == null) {
|
||||
return center;
|
||||
}
|
||||
return new Point2D.Double((line.getX1() + line.getX2()) / 2.0, (line.getY1() + line.getY2()) / 2.0);
|
||||
}
|
||||
|
||||
private static Point2D getOptimalCenter(GeneralPath generalPath, Point2D center) {
|
||||
double dist;
|
||||
Point2D endPt;
|
||||
Point2D startPt;
|
||||
Vector<Point2D> points;
|
||||
double angle;
|
||||
Point2D.Double rCenter = new Point2D.Double(center.getX(), center.getY());
|
||||
Point2D initStartPt = null;
|
||||
Point2D initEndPt = null;
|
||||
double maxDist = 0.0;
|
||||
int i = -5;
|
||||
while (i < 7) {
|
||||
angle = Math.PI * (double)i / 12.0;
|
||||
points = AWTLabelUtil.getIntersectPoints(generalPath, rCenter, angle);
|
||||
int j = 0;
|
||||
while (j < points.size() - 1) {
|
||||
startPt = points.get(j);
|
||||
endPt = points.get(j + 1);
|
||||
if (!(startPt.getX() < ((Point2D)rCenter).getX() && ((Point2D)rCenter).getX() > endPt.getX() || startPt.getY() > ((Point2D)rCenter).getY() && ((Point2D)rCenter).getY() < endPt.getY() || !((dist = Point2D.distance(startPt.getX(), startPt.getY(), endPt.getX(), endPt.getY())) >= maxDist))) {
|
||||
maxDist = dist;
|
||||
if (initStartPt == null || initEndPt == null) {
|
||||
initStartPt = new Point2D.Double(startPt.getX(), startPt.getY());
|
||||
initEndPt = new Point2D.Double(endPt.getX(), endPt.getY());
|
||||
} else {
|
||||
initStartPt.setLocation(startPt);
|
||||
initEndPt.setLocation(endPt);
|
||||
}
|
||||
}
|
||||
++j;
|
||||
}
|
||||
if (initStartPt == null || initEndPt == null) {
|
||||
return center;
|
||||
}
|
||||
((Point2D)rCenter).setLocation((initStartPt.getX() + initEndPt.getX()) / 2.0, (initStartPt.getY() + initEndPt.getY()) / 2.0);
|
||||
++i;
|
||||
++i;
|
||||
}
|
||||
angle = AWTLabelUtil.calcMainAngle(generalPath);
|
||||
points = AWTLabelUtil.getIntersectPoints(generalPath, rCenter, Math.toRadians(angle));
|
||||
double minDist = Double.MAX_VALUE;
|
||||
int j = 0;
|
||||
while (j < points.size() - 1) {
|
||||
startPt = points.get(j);
|
||||
endPt = points.get(j + 1);
|
||||
if (!(startPt.getX() < ((Point2D)rCenter).getX() && ((Point2D)rCenter).getX() > endPt.getX() || startPt.getY() > ((Point2D)rCenter).getY() && ((Point2D)rCenter).getY() < endPt.getY() || !((dist = Point2D.distance(startPt.getX(), startPt.getY(), endPt.getX(), endPt.getY())) < minDist))) {
|
||||
minDist = dist;
|
||||
initStartPt = new Point2D.Double(startPt.getX(), startPt.getY());
|
||||
initEndPt = new Point2D.Double(endPt.getX(), endPt.getY());
|
||||
}
|
||||
++j;
|
||||
}
|
||||
double d = generalPath.getBounds2D().getHeight() > generalPath.getBounds2D().getWidth() ? generalPath.getBounds2D().getHeight() : generalPath.getBounds2D().getWidth();
|
||||
if (maxDist * 10.0 < d) {
|
||||
return center;
|
||||
}
|
||||
return new Point2D.Double((initStartPt.getX() + initEndPt.getX()) / 2.0, (initStartPt.getY() + initEndPt.getY()) / 2.0);
|
||||
}
|
||||
|
||||
private static Line2D getIntersectLineHV(Vector<Point2D> points, Point2D point) {
|
||||
if (points.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
Line2D.Double maxLine = null;
|
||||
double maxDist = 0.0;
|
||||
int i = 0;
|
||||
while (i < points.size() - 1) {
|
||||
Point2D sp1 = points.get(i);
|
||||
Point2D sp2 = points.get(i + 1);
|
||||
if (Math.min(sp1.getX(), sp2.getX()) <= point.getX() && point.getX() <= Math.max(sp1.getX(), sp2.getX()) && Math.min(sp1.getY(), sp2.getY()) <= point.getY() && point.getY() <= Math.max(sp1.getY(), sp2.getY())) {
|
||||
return new Line2D.Double(sp1, sp2);
|
||||
}
|
||||
double currentDist = sp1.distance(sp2);
|
||||
if (maxDist < currentDist) {
|
||||
maxDist = currentDist;
|
||||
maxLine = new Line2D.Double(sp1, sp2);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static double calcMainAngle(GeneralPath path) {
|
||||
double[] lineLength = AWTLabelUtil.calcAngleFactor(path);
|
||||
int maxIndex = 0;
|
||||
double maxLength = lineLength[0];
|
||||
int i = 1;
|
||||
while (i < lineLength.length) {
|
||||
if (maxLength < lineLength[i]) {
|
||||
maxIndex = i;
|
||||
maxLength = lineLength[i];
|
||||
}
|
||||
++i;
|
||||
}
|
||||
int angle = maxIndex * 10;
|
||||
if (angle > 90) {
|
||||
return angle - 180;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
private static double[] calcAngleFactor(GeneralPath path) {
|
||||
double[] lineLength = new double[18];
|
||||
double[] startCoords = new double[6];
|
||||
double[] currentCoords = new double[6];
|
||||
int type = -1;
|
||||
double subAngle = 0.0;
|
||||
PathIterator pathIter = path.getPathIterator(new AffineTransform());
|
||||
while (!pathIter.isDone()) {
|
||||
type = pathIter.currentSegment(currentCoords);
|
||||
if (type != 0 && type == 1 && startCoords[0] != currentCoords[0] && startCoords[1] != currentCoords[1]) {
|
||||
subAngle = AWTLabelUtil.getAbsoluteAngle(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1]);
|
||||
int index = (int)(subAngle >= 175.0 ? 0.0 : (subAngle + 5.0) / 10.0);
|
||||
double dist = Point2D.distance(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1]);
|
||||
lineLength[index] = lineLength[index] + dist;
|
||||
}
|
||||
startCoords = Arrays.copyOf(currentCoords, currentCoords.length);
|
||||
pathIter.next();
|
||||
}
|
||||
return lineLength;
|
||||
}
|
||||
|
||||
private static Point2D getCrossLineCenter(GeneralPath path, Point2D point) {
|
||||
Vector<Point2D> hPoints = AWTLabelUtil.getIntersectPoints(path, point, 0.0);
|
||||
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(path, point, 1.5707963267948966);
|
||||
Vector<Line2D> hLines = AWTLabelUtil.getContainLines(path, hPoints);
|
||||
Vector<Line2D> vLines = AWTLabelUtil.getContainLines(path, vPoints);
|
||||
double maxHDist = 0.0;
|
||||
Line2D maxHLine = null;
|
||||
double dist = 0.0;
|
||||
for (Line2D line : hLines) {
|
||||
dist = Math.abs(line.getX1() - line.getX2());
|
||||
if (!(maxHDist < dist)) continue;
|
||||
maxHDist = dist;
|
||||
maxHLine = line;
|
||||
}
|
||||
double maxVDist = 0.0;
|
||||
Line2D maxVLine = null;
|
||||
for (Line2D line : vLines) {
|
||||
point = new Point2D.Double(line.getX1(), (line.getY1() + line.getY2()) / 2.0);
|
||||
hPoints = AWTLabelUtil.getIntersectPoints(path, point, 0.0);
|
||||
if ((line = AWTLabelUtil.getIntersectLineH(hPoints, point)) == null || !(maxVDist < (dist = Math.abs(line.getX1() - line.getX2())))) continue;
|
||||
maxVDist = dist;
|
||||
maxVLine = line;
|
||||
}
|
||||
if (maxHLine == null && maxVLine == null) {
|
||||
return null;
|
||||
}
|
||||
if (maxHLine == null) {
|
||||
return AWTLabelUtil.refineLineCenterV(path, maxVLine);
|
||||
}
|
||||
if (maxVLine == null) {
|
||||
return AWTLabelUtil.refineLineCenterH(path, maxHLine);
|
||||
}
|
||||
if (maxHDist > maxVDist) {
|
||||
return AWTLabelUtil.refineLineCenterH(path, maxHLine);
|
||||
}
|
||||
return AWTLabelUtil.refineLineCenterV(path, maxVLine);
|
||||
}
|
||||
|
||||
private static Point2D refineLineCenterV(GeneralPath path, Line2D line) {
|
||||
return new Point2D.Double((line.getX1() + line.getX2()) / 2.0, line.getY1());
|
||||
}
|
||||
|
||||
private static Point2D refineLineCenterH(GeneralPath path, Line2D line) {
|
||||
Point2D.Double center = new Point2D.Double((line.getX1() + line.getX2()) / 2.0, line.getY1());
|
||||
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(path, center, 1.5707963267948966);
|
||||
Line2D vLine = AWTLabelUtil.getIntersectLineV(vPoints, center);
|
||||
if (vLine == null) {
|
||||
return center;
|
||||
}
|
||||
return new Point2D.Double(vLine.getX1(), (vLine.getY1() + vLine.getY2()) / 2.0);
|
||||
}
|
||||
|
||||
private static Line2D getIntersectLineH(Vector<Point2D> points, Point2D point) {
|
||||
if (points.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < points.size() - 1) {
|
||||
Point2D sp1 = points.get(i);
|
||||
Point2D sp2 = points.get(i + 1);
|
||||
if (Math.min(sp1.getX(), sp2.getX()) <= point.getX() && point.getX() <= Math.max(sp1.getX(), sp2.getX())) {
|
||||
return new Line2D.Double(sp1, sp2);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Line2D getIntersectLineV(Vector<Point2D> points, Point2D point) {
|
||||
if (points.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < points.size() - 1) {
|
||||
Point2D sp1 = points.get(i);
|
||||
Point2D sp2 = points.get(i + 1);
|
||||
if (Math.min(sp1.getY(), sp2.getY()) <= point.getY() && point.getY() <= Math.max(sp1.getY(), sp2.getY())) {
|
||||
return new Line2D.Double(sp1, sp2);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Vector<Line2D> getContainLines(GeneralPath path, Vector<Point2D> points) {
|
||||
if (points.size() < 2) {
|
||||
return new Vector<Line2D>();
|
||||
}
|
||||
Vector<Line2D> lines = new Vector<Line2D>();
|
||||
int i = 0;
|
||||
while (i < points.size() - 1) {
|
||||
double cy;
|
||||
double cx;
|
||||
Point2D sp1 = points.get(i);
|
||||
Point2D sp2 = points.get(i + 1);
|
||||
if (sp1.getX() == sp2.getX()) {
|
||||
cx = sp1.getX();
|
||||
cy = (sp1.getY() + sp2.getY()) / 2.0;
|
||||
} else {
|
||||
cx = (sp1.getX() + sp2.getX()) / 2.0;
|
||||
cy = sp1.getY();
|
||||
}
|
||||
if (path.contains(cx, cy)) {
|
||||
lines.add(new Line2D.Double(sp1, sp2));
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static Vector<Point2D> getIntersectPoints(GeneralPath path, Point2D point, double angle) {
|
||||
Vector<Point2D> holder = new Vector<Point2D>();
|
||||
Line2D baseLine = AWTLabelUtil.getBoundCuttingLine(path.getBounds2D(), point, angle);
|
||||
double a1 = Math.tan(angle);
|
||||
double b1 = point.getY() - a1 * point.getX();
|
||||
double[] startCoords = new double[6];
|
||||
double[] currentCoords = new double[6];
|
||||
int type = -1;
|
||||
double subAngle = 0.0;
|
||||
PathIterator pathIter = path.getPathIterator(new AffineTransform());
|
||||
while (!pathIter.isDone()) {
|
||||
type = pathIter.currentSegment(currentCoords);
|
||||
if (type != 0 && type == 1 && startCoords[0] != currentCoords[0] && startCoords[1] != currentCoords[1] && angle != (subAngle = AWTLabelUtil.getAngle(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1])) && baseLine.intersectsLine(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1])) {
|
||||
double y;
|
||||
double x;
|
||||
double a2 = Math.tan(subAngle);
|
||||
double b2 = currentCoords[1] - a2 * currentCoords[0];
|
||||
if (angle == 1.5707963267948966) {
|
||||
x = point.getX();
|
||||
y = a2 * x + b2;
|
||||
} else if (subAngle == 1.5707963267948966) {
|
||||
x = currentCoords[0];
|
||||
y = a1 * x + b1;
|
||||
} else {
|
||||
x = (b2 - b1) / (a1 - a2);
|
||||
y = (a1 * b2 - a2 * b1) / (a1 - a2);
|
||||
}
|
||||
AWTLabelUtil.addPointBySort(holder, new Point2D.Double(x, y));
|
||||
}
|
||||
startCoords = Arrays.copyOf(currentCoords, currentCoords.length);
|
||||
pathIter.next();
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
|
||||
private static void addPointBySort(Vector<Point2D> holder, Point2D point) {
|
||||
boolean inserted = false;
|
||||
int i = 0;
|
||||
while (i < holder.size()) {
|
||||
Point2D current_point = holder.get(i);
|
||||
if (point.getX() < current_point.getX()) {
|
||||
holder.add(i, point);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
if (point.getX() == current_point.getX() && point.getY() < current_point.getY()) {
|
||||
holder.add(i, point);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (!inserted) {
|
||||
holder.add(point);
|
||||
}
|
||||
}
|
||||
|
||||
private static Line2D getBoundCuttingLine(Rectangle2D bound, Point2D point, double angle) {
|
||||
double minx = bound.getMinX() - 10.0;
|
||||
double miny = bound.getMinY() - 10.0;
|
||||
double maxx = bound.getMaxX() + 10.0;
|
||||
double maxy = bound.getMaxY() + 10.0;
|
||||
Line2D.Double line = angle == 1.5707963267948966 ? new Line2D.Double(point.getX(), miny, point.getX(), maxy) : (angle == 0.0 ? new Line2D.Double(minx, point.getY(), maxx, point.getY()) : new Line2D.Double(minx, point.getY() - (point.getX() - minx) * Math.tan(angle), maxx, point.getY() + (maxx - point.getX()) * Math.tan(angle)));
|
||||
return line;
|
||||
}
|
||||
|
||||
private static double getAngle(double x1, double y1, double x2, double y2) {
|
||||
Point2D.Double pt = new Point2D.Double(x2 - x1, y2 - y1);
|
||||
if (((Point2D)pt).getX() == 0.0 && ((Point2D)pt).getY() == 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
if (((Point2D)pt).getY() == 0.0) {
|
||||
if (((Point2D)pt).getX() > 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
return Math.PI;
|
||||
}
|
||||
if (((Point2D)pt).getX() == 0.0) {
|
||||
if (((Point2D)pt).getY() > 0.0) {
|
||||
return 1.5707963267948966;
|
||||
}
|
||||
return 4.71238898038469;
|
||||
}
|
||||
if (((Point2D)pt).getX() > 0.0) {
|
||||
if (((Point2D)pt).getY() > 0.0) {
|
||||
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX());
|
||||
}
|
||||
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX()) + Math.PI * 2;
|
||||
}
|
||||
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX()) + Math.PI;
|
||||
}
|
||||
|
||||
private static double getAbsoluteAngle(double x1, double y1, double x2, double y2) {
|
||||
if (y1 == y2) {
|
||||
return 0.0;
|
||||
}
|
||||
if (x1 == x2) {
|
||||
return 90.0;
|
||||
}
|
||||
boolean excessRightAngle = false;
|
||||
if (x1 > x2 && y1 < y2 || x1 < x2 && y1 > y2) {
|
||||
excessRightAngle = true;
|
||||
}
|
||||
double base = Math.abs(x1 - x2);
|
||||
double height = Math.abs(y1 - y2);
|
||||
double r_angle = Math.atan(height / base);
|
||||
if (excessRightAngle) {
|
||||
return Math.toDegrees(Math.PI - r_angle);
|
||||
}
|
||||
return Math.toDegrees(r_angle);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public abstract class AbstractService
|
||||
extends HttpServlet {
|
||||
private static final long serialVersionUID = 2014061020172321L;
|
||||
|
||||
public abstract Object parseQuery(HttpServletRequest var1) throws Exception;
|
||||
|
||||
public abstract String doProcess(String var1);
|
||||
|
||||
public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
|
||||
super.service(arg0, arg1);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doGet(req, resp);
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doPost(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.AbstractList;
|
||||
|
||||
public class AttributeList extends AbstractList
|
||||
{
|
||||
final Object ARRAY;
|
||||
final int OFFSET;
|
||||
final int LEN;
|
||||
final int SIZE;
|
||||
final int START;
|
||||
final int END;
|
||||
final int STEP;
|
||||
|
||||
public AttributeList(Object array)
|
||||
{
|
||||
this(array, 0, 1);
|
||||
}
|
||||
|
||||
public AttributeList(Object array, int offset, int len) {
|
||||
this(array, offset, len, 0, Array.getLength(array));
|
||||
}
|
||||
|
||||
public AttributeList(Object array, int offset, int len, int start, int end) {
|
||||
this.START = start;
|
||||
this.END = end;
|
||||
this.ARRAY = array;
|
||||
this.OFFSET = offset;
|
||||
this.LEN = len;
|
||||
this.SIZE = (Math.abs(this.START - this.END) / this.LEN);
|
||||
this.STEP = (this.START < this.END ? this.LEN : -this.LEN);
|
||||
|
||||
if (!this.ARRAY.getClass().isArray()) {
|
||||
throw new IllegalArgumentException("Provided argument was not an array");
|
||||
}
|
||||
if (Array.getLength(this.ARRAY) % this.LEN != 0)
|
||||
throw new IllegalArgumentException(
|
||||
"You have requested Coordiantes of " + this.LEN + " ordinates. " +
|
||||
"This is inconsistent with an array of length " + Array.getLength(this.ARRAY));
|
||||
}
|
||||
|
||||
public Object get(int index)
|
||||
{
|
||||
rangeCheck(index);
|
||||
return Array.get(this.ARRAY, this.START + this.STEP * index + this.OFFSET);
|
||||
}
|
||||
|
||||
public double getDouble(int index) {
|
||||
rangeCheck(index);
|
||||
return Array.getDouble(this.ARRAY, this.START + this.STEP * index + this.OFFSET);
|
||||
}
|
||||
public String getString(int index) {
|
||||
rangeCheck(index);
|
||||
return Array.get(this.ARRAY, this.START + this.STEP * index + this.OFFSET).toString();
|
||||
}
|
||||
public double[] toDoubleArray() {
|
||||
double[] array = new double[size()];
|
||||
for (int i = 0; i < size(); i++) {
|
||||
array[i] = getDouble(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
public Object[] toObjectArray() {
|
||||
Object[] array = new Object[size()];
|
||||
for (int i = 0; i < size(); i++) {
|
||||
array[i] = get(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private void rangeCheck(int index)
|
||||
{
|
||||
if (index >= this.SIZE)
|
||||
throw new IndexOutOfBoundsException(
|
||||
"Index: " + index + ", Size: " + this.SIZE);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.SIZE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,305 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.geotools.factory.GeoTools;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.referencing.ReferencingFactoryFinder;
|
||||
import org.geotools.util.NameFactory;
|
||||
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.util.GenericName;
|
||||
|
||||
public class CRSMngr
|
||||
{
|
||||
private static final O2CRSFactory crsFactory = new O2CRSFactory();
|
||||
private static final O2CRSOverrideFactory overrideFactory = new O2CRSOverrideFactory();
|
||||
|
||||
static
|
||||
{
|
||||
System.setProperty("org.geotools.referencing.forceXY", "true");
|
||||
Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.valueOf(true));
|
||||
GeoTools.fireConfigurationChanged();
|
||||
|
||||
ReferencingFactoryFinder.addAuthorityFactory(crsFactory);
|
||||
ReferencingFactoryFinder.addAuthorityFactory(overrideFactory);
|
||||
}
|
||||
|
||||
public static CoordinateReferenceSystem getCRS(Integer code)
|
||||
{
|
||||
return getCRS(String.valueOf(code), true);
|
||||
}
|
||||
|
||||
public static CoordinateReferenceSystem getCRS(String code) {
|
||||
return getCRS(code, true);
|
||||
}
|
||||
|
||||
public static CoordinateReferenceSystem getCRS(String code, boolean useEPSG)
|
||||
{
|
||||
try {
|
||||
code = code.trim();
|
||||
|
||||
GenericName name = NameFactory.create(code);
|
||||
if ((name.scope().name() == null) && (useEPSG)) {
|
||||
code = "EPSG:" + code;
|
||||
}
|
||||
|
||||
return CRS.decode(code, true);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "CRS [" + code + "] is not exist.");
|
||||
}return null;
|
||||
}
|
||||
|
||||
public static CoordinateReferenceSystem getLayerCRS(int srid, boolean useEPSG)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = null;
|
||||
try
|
||||
{
|
||||
crs = crsFactory.getCRS(srid);
|
||||
|
||||
return overrideFactory.createCoordinateReferenceSystem(CRS.toSRS(crs));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (crs != null) {
|
||||
return crs;
|
||||
}
|
||||
|
||||
LogMngr.getInstance().logError("[CRS]", "SRID [" + srid + "] is not exist.");
|
||||
|
||||
if (useEPSG) {
|
||||
try
|
||||
{
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Try to find SRID from EPSG [EPSG:" + srid + "]");
|
||||
return CRS.decode("EPSG:" + srid, true);
|
||||
} catch (Exception e2) {
|
||||
LogMngr.getInstance().logError("[CRS]", "SRID [EPSG:" + srid + "] is not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
||||
}
|
||||
|
||||
private static void updateLayerCRS()
|
||||
throws Exception
|
||||
{
|
||||
Map map = ServerContext.getMap();
|
||||
synchronized (map)
|
||||
{
|
||||
Iterator iter = map.getAllLayers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Layer layer = (Layer)iter.next();
|
||||
layer.updateCRS();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLayerCRS(CoordinateReferenceSystem targetCRS)
|
||||
throws Exception
|
||||
{
|
||||
Map map = ServerContext.getMap();
|
||||
synchronized (map)
|
||||
{
|
||||
Iterator iter = map.getAllLayers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Layer layer = (Layer)iter.next();
|
||||
|
||||
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(CRS.toSRS(targetCRS)))
|
||||
layer.updateCRS();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLayerCRS(String code)
|
||||
throws Exception
|
||||
{
|
||||
Map map = ServerContext.getMap();
|
||||
synchronized (map)
|
||||
{
|
||||
Iterator iter = map.getAllLayers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Layer layer = (Layer)iter.next();
|
||||
|
||||
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(code))
|
||||
layer.updateCRS();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertBasicCRS(int srid, String auth, String code, String wkt)
|
||||
throws Exception
|
||||
{
|
||||
insertBasicCRS(srid, auth, code, wkt, false);
|
||||
}
|
||||
|
||||
public static void insertBasicCRS(int srid, String auth, String code, String wkt, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = null;
|
||||
try {
|
||||
crs = crsFactory.parseWKT(auth, code, wkt);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("CoordinateReferenceSystem is not valid.");
|
||||
}
|
||||
|
||||
crsFactory.insertCRS(srid, auth, code, crs, write);
|
||||
}
|
||||
|
||||
public static void updateBasicCRS(int srid, String auth, String code, String wkt) throws Exception
|
||||
{
|
||||
updateBasicCRS(srid, auth, code, wkt, false);
|
||||
}
|
||||
|
||||
public static void updateBasicCRS(int srid, String auth, String code, String wkt, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = null;
|
||||
try {
|
||||
crs = crsFactory.parseWKT(auth, code, wkt);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("CoordinateReferenceSystem is not valid.");
|
||||
}
|
||||
|
||||
crsFactory.updateCRS(srid, auth, code, crs, write);
|
||||
|
||||
updateLayerCRS(crs);
|
||||
}
|
||||
|
||||
public static void removeBasicCRS(int srid) throws Exception
|
||||
{
|
||||
removeBasicCRS(srid, false);
|
||||
}
|
||||
|
||||
public static void removeBasicCRS(int srid, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = crsFactory.getCRS(srid);
|
||||
|
||||
if (isUsedByLayer(crs)) {
|
||||
throw new IllegalArgumentException("SRID [" + srid + "] is used by Layer.");
|
||||
}
|
||||
|
||||
crsFactory.removeCRS(srid, write);
|
||||
}
|
||||
|
||||
public static void insertOverrideCRS(String auth, String code, String wkt)
|
||||
throws Exception
|
||||
{
|
||||
insertOverrideCRS(auth, code, wkt, false);
|
||||
}
|
||||
|
||||
public static void insertOverrideCRS(String auth, String code, String wkt, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = null;
|
||||
try {
|
||||
crs = overrideFactory.parseWKT(auth, code, wkt);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("CoordinateReferenceSystem is not valid.");
|
||||
}
|
||||
|
||||
overrideFactory.insertCRS(auth, code, crs, write);
|
||||
}
|
||||
|
||||
public static void updateOverrideCRS(String auth, String code, String wkt) throws Exception
|
||||
{
|
||||
updateOverrideCRS(auth, code, wkt, false);
|
||||
}
|
||||
|
||||
public static void updateOverrideCRS(String auth, String code, String wkt, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = null;
|
||||
try {
|
||||
crs = overrideFactory.parseWKT(auth, code, wkt);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("CoordinateReferenceSystem is not valid.");
|
||||
}
|
||||
|
||||
overrideFactory.updateCRS(auth, code, crs, write);
|
||||
|
||||
String crsKey = auth.trim().toUpperCase() + ":" + code.trim().toUpperCase();
|
||||
updateLayerCRS(crsKey);
|
||||
}
|
||||
|
||||
public static void removeOverrideCRS(String auth, String code)
|
||||
throws Exception
|
||||
{
|
||||
removeOverrideCRS(auth, code, false);
|
||||
}
|
||||
|
||||
public static void removeOverrideCRS(String auth, String code, boolean write)
|
||||
throws Exception
|
||||
{
|
||||
CoordinateReferenceSystem crs = overrideFactory.getCRS(auth, code);
|
||||
String crsKey = auth.trim().toUpperCase() + ":" + code.trim().toUpperCase();
|
||||
|
||||
if (isUsedByLayer(crs)) {
|
||||
throw new IllegalArgumentException("CODE [Authority:" + auth + "] or [Code:" + code + "] is used by Layer.");
|
||||
}
|
||||
|
||||
overrideFactory.removeCRS(auth, code, write);
|
||||
|
||||
updateLayerCRS(crsKey);
|
||||
}
|
||||
|
||||
private static boolean isUsedByLayer(String code)
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
Iterator iter = ServerContext.getMap().getAllLayers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Layer layer = (Layer)iter.next();
|
||||
|
||||
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(code))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[CRS]", "isUsedByLayer Fail [CODE:" + code + "] :: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isUsedByLayer(CoordinateReferenceSystem targetCRS) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
Iterator iter = ServerContext.getMap().getAllLayers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Layer layer = (Layer)iter.next();
|
||||
|
||||
if (CRS.equalsIgnoreMetadata(layer.getCRS(), targetCRS))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[CRS]", "isUsedByLayer Fail [CODE:" + targetCRS + "] :: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void reloadServiceCRS(boolean updateLayer) throws Exception
|
||||
{
|
||||
crsFactory.initCrsDefinitions();
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Success to Reload BasicCRS");
|
||||
overrideFactory.initCrsDefinitions();
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Success to Reload OverrideCRS");
|
||||
|
||||
if (updateLayer)
|
||||
try {
|
||||
updateLayerCRS();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Fail to Update Layer CRS :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
public class CacheFormat {
|
||||
int width = 256;
|
||||
int height = 256;
|
||||
String format = "png";
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import javax.management.modelmbean.XMLParseException;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class CacheLevel {
|
||||
private CacheLevelSet levelSet;
|
||||
private final int level;
|
||||
private Double resolution;
|
||||
private Double scaleDenominator;
|
||||
|
||||
public CacheLevel(Integer lv, Double res, Double scale) throws Exception {
|
||||
this.level = lv;
|
||||
this.resolution = res;
|
||||
this.scaleDenominator = scale;
|
||||
if (this.resolution == null && this.scaleDenominator == null) {
|
||||
throw new XMLParseException("<MATRIX> Attribute value [RESOLUTION or SCALE] is null. LEVEL [" + this.level + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public Double getResolution() {
|
||||
return this.resolution;
|
||||
}
|
||||
|
||||
public Double getScale() {
|
||||
return this.scaleDenominator;
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return this.levelSet.getBBox();
|
||||
}
|
||||
|
||||
public int getCacheSizeW() {
|
||||
return this.levelSet.getCacheSizeW();
|
||||
}
|
||||
|
||||
public int getCacheSizeH() {
|
||||
return this.levelSet.getCacheSizeH();
|
||||
}
|
||||
|
||||
public File getCachePath() {
|
||||
return new File(this.levelSet.getCacheDir(), "/" + this.level);
|
||||
}
|
||||
|
||||
public String getCacheFormat() {
|
||||
return this.levelSet.getCacheFormat();
|
||||
}
|
||||
|
||||
public String getLayerName() {
|
||||
return this.levelSet.getLayerName();
|
||||
}
|
||||
|
||||
public String getLayerStyle() {
|
||||
return this.levelSet.getLayerStyle();
|
||||
}
|
||||
|
||||
public void refineCacheLevel(CacheLevelSet lSet) throws Exception {
|
||||
this.levelSet = lSet;
|
||||
if (this.resolution == null) {
|
||||
this.resolution = lSet.calResolution(this.scaleDenominator);
|
||||
} else if (this.scaleDenominator == null) {
|
||||
this.scaleDenominator = lSet.calScaleDenominator(this.resolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.TreeMap;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.opengis.referencing.crs.GeographicCRS;
|
||||
|
||||
public class CacheLevelSet {
|
||||
private final double dpi = 90.7142857142857;
|
||||
private final double OGC_DEGREE_TO_METER = 111319.49079327358;
|
||||
private final double OGC_INCH_TO_METER = 0.0254;
|
||||
private final boolean isTopLeft = false;
|
||||
private ImgCacheLayer cacheLayer;
|
||||
private TreeMap<Integer, CacheLevel> levelSet = new TreeMap();
|
||||
|
||||
public CacheLevelSet copy() throws Exception {
|
||||
CacheLevelSet copy = new CacheLevelSet();
|
||||
for (CacheLevel lvl : this.levelSet.values()) {
|
||||
CacheLevel level = new CacheLevel(Integer.valueOf(lvl.getLevel()), lvl.getResolution(), lvl.getScale());
|
||||
copy.addLevel(level);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void addLevel(CacheLevel lvl) {
|
||||
this.levelSet.put(lvl.getLevel(), lvl);
|
||||
}
|
||||
|
||||
public CacheLevel getLevel(double res) {
|
||||
CacheLevel level = null;
|
||||
for (CacheLevel lvl : this.levelSet.values()) {
|
||||
if (level == null) {
|
||||
level = lvl;
|
||||
continue;
|
||||
}
|
||||
if (!(Math.abs(level.getResolution() - res) > Math.abs(lvl.getResolution() - res))) continue;
|
||||
level = lvl;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return this.cacheLayer.getBBox();
|
||||
}
|
||||
|
||||
public int getCacheSizeW() {
|
||||
return this.cacheLayer.getCacheSizeW();
|
||||
}
|
||||
|
||||
public int getCacheSizeH() {
|
||||
return this.cacheLayer.getCacheSizeH();
|
||||
}
|
||||
|
||||
public File getCacheDir() {
|
||||
return this.cacheLayer.getCacheDir();
|
||||
}
|
||||
|
||||
public String getCacheFormat() {
|
||||
return this.cacheLayer.getCacheFormat();
|
||||
}
|
||||
|
||||
public String getLayerName() {
|
||||
return this.cacheLayer.getLayerName();
|
||||
}
|
||||
|
||||
public String getLayerStyle() {
|
||||
return this.cacheLayer.getLayerStyle();
|
||||
}
|
||||
|
||||
public boolean isTopLeft() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public double calScaleDenominator(double res) {
|
||||
if (this.cacheLayer.getBBox().getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||
return res * 111319.49079327358 / 2.8000000000000003E-4;
|
||||
}
|
||||
return res / 2.8000000000000003E-4;
|
||||
}
|
||||
|
||||
public double calResolution(double scale) {
|
||||
if (this.cacheLayer.getBBox().getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||
return scale * 2.8000000000000003E-4 * 8.983152841195214E-6;
|
||||
}
|
||||
return scale * 2.8000000000000003E-4;
|
||||
}
|
||||
|
||||
public void refindCacheLevelSet(ImgCacheLayer clayer) throws Exception {
|
||||
this.cacheLayer = clayer;
|
||||
for (CacheLevel level : this.levelSet.values()) {
|
||||
level.refineCacheLevel(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.geotools.se.v1_1.SE;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ColorMapEntry;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.xml.AbstractComplexBinding;
|
||||
import org.geotools.xml.ElementInstance;
|
||||
import org.geotools.xml.InstanceComponent;
|
||||
import org.geotools.xml.Node;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
|
||||
public class CategorizeBinding110 extends AbstractComplexBinding
|
||||
{
|
||||
StyleFactory styleFactory;
|
||||
FilterFactory filterFactory;
|
||||
|
||||
public CategorizeBinding110(StyleFactory styleFactory, FilterFactory filterFactory)
|
||||
{
|
||||
this.styleFactory = styleFactory;
|
||||
this.filterFactory = filterFactory;
|
||||
}
|
||||
|
||||
public QName getTarget()
|
||||
{
|
||||
return SE.Categorize;
|
||||
}
|
||||
|
||||
public Class getType()
|
||||
{
|
||||
return ColorMap.class;
|
||||
}
|
||||
|
||||
public Object parse(ElementInstance instance, Node node, Object value)
|
||||
throws Exception
|
||||
{
|
||||
ColorMap map = this.styleFactory.createColorMap();
|
||||
|
||||
String type = (String)node.getAttributeValue("type");
|
||||
if ((type == null) || (type.equalsIgnoreCase("intervals")))
|
||||
map.setType(2);
|
||||
else {
|
||||
map.setType(3);
|
||||
}
|
||||
|
||||
List children = node.getChildren();
|
||||
int i = 0;
|
||||
while (!"Threshold".equals(((Node)children.get(i)).getComponent().getName())) {
|
||||
i++;
|
||||
}
|
||||
|
||||
while (i < children.size()) {
|
||||
ColorMapEntry entry = this.styleFactory.createColorMapEntry();
|
||||
|
||||
double quantity = Double.parseDouble(((Node)children.get(i)).getValue().toString());
|
||||
entry.setQuantity(this.filterFactory.literal(quantity));
|
||||
|
||||
if (i + 1 >= children.size()) {
|
||||
throw new IllegalArgumentException("Incorrectly specified color map Threshold/Value pair");
|
||||
}
|
||||
|
||||
String colorStr = ((Node)children.get(i + 1)).getValue().toString();
|
||||
Color color = ServerUtil.getColorFromHex(colorStr);
|
||||
|
||||
double opacity = color.getAlpha() / 255.0D;
|
||||
|
||||
entry.setOpacity(this.filterFactory.literal(String.format("%.2f", new Object[] { Double.valueOf(opacity) })));
|
||||
entry.setColor(this.filterFactory.literal(ServerUtil.getHexFromColor(color)));
|
||||
|
||||
map.addColorMapEntry(entry);
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class ConnJDBC {
|
||||
protected Connection connection = null;
|
||||
|
||||
public ConnJDBC() {
|
||||
DriverManager.setLoginTimeout(5);
|
||||
}
|
||||
|
||||
public Connection openConn() throws Exception {
|
||||
if (this.connection != null) {
|
||||
return this.connection;
|
||||
}
|
||||
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||
String sURL = this.getJDBCUrl();
|
||||
String user = (String)map.get("conf.xml.map.user");
|
||||
String passwd = (String)map.get("conf.xml.map.passwd");
|
||||
try {
|
||||
Class.forName(this.getDriverClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Can't register JDBC Driver :: " + e.getMessage());
|
||||
throw new Exception("Can't register JDBC Driver :: " + e.getMessage());
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logDebug("[DB]", "Open Connection :: " + sURL + ", " + user + ", " + passwd);
|
||||
this.connection = DriverManager.getConnection(sURL, user, passwd);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Open Connection Fail :: " + e.getMessage());
|
||||
throw new SQLException("Open Connection Fail :: " + e.getMessage());
|
||||
}
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public void closeConn() {
|
||||
if (this.connection != null) {
|
||||
try {
|
||||
if (!this.connection.isClosed()) {
|
||||
this.connection.close();
|
||||
}
|
||||
this.connection = null;
|
||||
}
|
||||
catch (SQLException e) {
|
||||
this.connection = null;
|
||||
LogMngr.getInstance().logError("[DB]", "Close Connection Fail :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getJDBCUrl() throws Exception {
|
||||
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||
String host = (String)map.get("conf.xml.map.host");
|
||||
String port = (String)map.get("conf.xml.map.port");
|
||||
String database = (String)map.get("conf.xml.map.database");
|
||||
return this.getJDBCUrl(host, Integer.valueOf(port), database);
|
||||
}
|
||||
|
||||
public abstract String getDriverClassName();
|
||||
|
||||
public abstract String getJDBCUrl(String var1, Integer var2, String var3);
|
||||
|
||||
public abstract FieldSQL getFieldSQL();
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnMngr
|
||||
{
|
||||
private static ConnMngr instance = null;
|
||||
private ConnJDBC connJDBC = null;
|
||||
|
||||
public static ConnMngr getInstance()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new ConnMngr();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ConnJDBC getConnObj(String dbType) throws Exception
|
||||
{
|
||||
if ((dbType != null) && (dbType.toLowerCase().equals("oracle")))
|
||||
return new ConnOracle();
|
||||
|
||||
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||
}
|
||||
|
||||
public ConnJDBC getConnObj(O2DSFactory.DBMSType dbType)
|
||||
throws Exception
|
||||
{
|
||||
if ((dbType != null) && (dbType == O2DSFactory.DBMSType.ORACLE))
|
||||
return new ConnOracle();
|
||||
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||
}
|
||||
|
||||
public Connection openConn()
|
||||
throws Exception
|
||||
{
|
||||
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||
|
||||
String dbType = (String)map.get("conf.xml.map.dbtype");
|
||||
dbType = dbType.trim();
|
||||
|
||||
if ((dbType != null) && (dbType.toLowerCase().equals("oracle"))) {
|
||||
this.connJDBC = new ConnOracle();
|
||||
} else {
|
||||
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||
}
|
||||
|
||||
return this.connJDBC.openConn();
|
||||
}
|
||||
|
||||
public void closeConn() {
|
||||
if (this.connJDBC != null)
|
||||
this.connJDBC.closeConn();
|
||||
}
|
||||
|
||||
public void closeSafe(Statement st)
|
||||
{
|
||||
if (st == null) {
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
st.close();
|
||||
} catch (SQLException localSQLException) {
|
||||
}
|
||||
}
|
||||
|
||||
public void closeSafe(ResultSet rs) {
|
||||
if (rs == null) {
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException localSQLException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnOracle extends ConnJDBC
|
||||
{
|
||||
public String getDriverClassName()
|
||||
{
|
||||
return "oracle.jdbc.driver.OracleDriver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database)
|
||||
{
|
||||
String sURL = "jdbc:oracle:thin:@";
|
||||
sURL = sURL + host + ":" + port + ":" + database;
|
||||
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL()
|
||||
{
|
||||
HashMap fields = new HashMap();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "SDO_GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR2");
|
||||
fields.put(FieldSQL.FieldType.NUMERIC, "NUMBER");
|
||||
fields.put(FieldSQL.FieldType.BOOLEAN, "CHAR(1)");
|
||||
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||
fields.put(FieldSQL.FieldType.BLOB, "BLOB");
|
||||
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR2(100)");
|
||||
|
||||
return new FieldSQL(O2DSFactory.DBMSType.ORACLE, fields, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap; // Map.Entry 대신 HashMap 사용을 명시
|
||||
import java.util.Map;
|
||||
|
||||
import org.geotools.data.Transaction;
|
||||
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.data.store.ContentDataStore;
|
||||
import org.geotools.data.store.ContentEntry; // ContentEntry는 여전히 사용될 수 있습니다.
|
||||
import org.geotools.data.store.ContentFeatureSource;
|
||||
import org.geotools.data.store.ContentState;
|
||||
import org.geotools.feature.AttributeTypeBuilder;
|
||||
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||
import org.geotools.jdbc.AutoGeneratedPrimaryKeyColumn;
|
||||
import org.geotools.jdbc.JDBCDataStore; // JDBCDataStore로 캐스팅하여 더 명확하게 사용
|
||||
import org.geotools.jdbc.JDBCState; // JDBCState는 여전히 사용될 수 있습니다.
|
||||
import org.geotools.jdbc.NonIncrementingPrimaryKeyColumn;
|
||||
import org.geotools.jdbc.NullPrimaryKey;
|
||||
import org.geotools.jdbc.PrimaryKey;
|
||||
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||
import org.geotools.jdbc.SequencedPrimaryKeyColumn;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class ContentDataStoreRefinder {
|
||||
|
||||
/**
|
||||
* JDBC DataStore의 FeatureType 스키마를 재구성합니다.
|
||||
* 주의: 이 메서드는 GeoTools의 내부 구조에 깊이 의존하므로,
|
||||
* GeoTools 버전 업데이트 시 호환성 문제가 발생할 수 있습니다.
|
||||
* 가능한 경우, JDBCDataStore.createSchema()를 통해 새로운 스키마를
|
||||
* 생성하거나 기존 데이터를 새 스키마로 마이그레이션하는 것을 권장합니다.
|
||||
*
|
||||
* @param dataStore 재구성할 JDBC DataStore
|
||||
* @param typeName 대상 FeatureType의 이름
|
||||
* @return 재구성된 ContentFeatureSource
|
||||
* @throws IOException
|
||||
*/
|
||||
public static synchronized ContentFeatureSource refindJDBCFeatureSource(ContentDataStore dataStore, String typeName) throws IOException {
|
||||
ContentFeatureSource cfs = dataStore.getFeatureSource(typeName);
|
||||
SimpleFeatureType featureType = cfs.getSchema();
|
||||
|
||||
SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder();
|
||||
tBuilder.init(featureType);
|
||||
tBuilder.setName(featureType.getTypeName().toUpperCase()); // 대문자로 FeatureType 이름 설정
|
||||
|
||||
AttributeTypeBuilder aBuilder = new AttributeTypeBuilder();
|
||||
for (AttributeDescriptor attr : featureType.getAttributeDescriptors()) {
|
||||
tBuilder.remove(attr.getLocalName()); // 기존 속성 제거 (이름 변경을 위해)
|
||||
|
||||
aBuilder.init(attr); // 기존 속성으로 초기화
|
||||
// 사용자 데이터 복사 (attr.getUserData()는 Map<Object, Object>를 반환)
|
||||
for (Map.Entry<Object, Object> entry : attr.getUserData().entrySet()) {
|
||||
aBuilder.addUserData(entry.getKey(), entry.getValue());
|
||||
}
|
||||
// 속성 이름을 대문자로 변경하여 추가
|
||||
tBuilder.add(aBuilder.buildDescriptor(attr.getLocalName().toUpperCase()));
|
||||
}
|
||||
|
||||
SimpleFeatureType nFeatureType = tBuilder.buildFeatureType();
|
||||
nFeatureType.getUserData().putAll(featureType.getUserData()); // FeatureType의 사용자 데이터 복사
|
||||
|
||||
// --- JDBCDataStore의 내부 상태 직접 조작은 매우 위험하며, GeoTools 버전 업데이트 시 깨질 수 있습니다. ---
|
||||
// JDBCState는 JDBCDataStore 내부에서 관리되는 상태 객체입니다.
|
||||
// ContentEntry를 새로 생성하여 상태를 주입하는 방식은 GeoTools의 일반적인 사용 패턴이 아닙니다.
|
||||
// 대신, JDBCDataStore가 스키마를 관리하는 방식을 따르는 것이 좋습니다.
|
||||
|
||||
// 여기서는 기존 로직의 의도를 최대한 살리려고 노력하지만,
|
||||
// 이 부분은 GeoTools 11.3에서 안전하게 작동하지 않을 수 있습니다.
|
||||
// 이상적으로는 JDBCDataStore.createSchema(nFeatureType)를 호출하여
|
||||
// 새로운 스키마를 등록하는 것이 더 안전한 방법입니다.
|
||||
|
||||
// 기존 로직의 문제점: ContentDataStore.entries 필드는 protected이거나 private일 수 있어 직접 접근 불가.
|
||||
// ContentEntry 및 ContentState의 내부 조작 역시 권장되지 않음.
|
||||
// PrimaryKey 관련 로직도 JDBCDataStore의 createSchema 시점에 함께 정의되는 것이 일반적.
|
||||
|
||||
// 임시 해결책 (기존 로직의 의도 최대한 유지):
|
||||
// ContentEntry를 다시 생성하는 대신, 기존 FeatureSource의 Entry를 가져와 상태를 업데이트하는 시도
|
||||
// 이 또한 GeoTools 내부 구현에 의존하므로 불안정할 수 있습니다.
|
||||
ContentEntry existingEntry = cfs.getEntry();
|
||||
ContentState state = existingEntry.getState(Transaction.AUTO_COMMIT); // 기존 Entry의 상태 가져오기
|
||||
|
||||
if (state instanceof JDBCState) {
|
||||
JDBCState jdbcState = (JDBCState) state;
|
||||
jdbcState.setFeatureType(nFeatureType); // 새 FeatureType 설정
|
||||
|
||||
// PrimaryKey 로직: 기존의 PrimaryKey 정보를 가져와 새로운 FeatureType에 맞게 조정
|
||||
// 이 부분은 JDBCDataStore의 JDBCState가 PrimaryKey를 어떻게 관리하는지에 따라 달라집니다.
|
||||
// GeoTools의 jdbc 모듈 소스 코드를 직접 확인하는 것이 가장 정확합니다.
|
||||
PrimaryKey oldPK = jdbcState.getPrimaryKey(); // 이전 PrimaryKey 가져오기
|
||||
ArrayList<PrimaryKeyColumn> nColumns = new ArrayList<>(); // PrimaryKeyColumn 타입으로 명시
|
||||
|
||||
if (oldPK != null) {
|
||||
for (PrimaryKeyColumn column : oldPK.getColumns()) {
|
||||
String newColumnName = column.getName().toUpperCase(); // 컬럼 이름도 대문자로
|
||||
|
||||
if (column instanceof AutoGeneratedPrimaryKeyColumn) {
|
||||
nColumns.add(new AutoGeneratedPrimaryKeyColumn(newColumnName, column.getType()));
|
||||
} else if (column instanceof SequencedPrimaryKeyColumn) {
|
||||
nColumns.add(new SequencedPrimaryKeyColumn(newColumnName, column.getType(), ((SequencedPrimaryKeyColumn) column).getSequenceName()));
|
||||
} else if (column instanceof NonIncrementingPrimaryKeyColumn) {
|
||||
nColumns.add(new NonIncrementingPrimaryKeyColumn(newColumnName, column.getType()));
|
||||
}
|
||||
// 다른 PrimaryKeyColumn 타입이 있다면 여기에 추가
|
||||
}
|
||||
}
|
||||
|
||||
if (nColumns.isEmpty()) {
|
||||
jdbcState.setPrimaryKey(new NullPrimaryKey(nFeatureType.getTypeName()));
|
||||
} else {
|
||||
jdbcState.setPrimaryKey(new PrimaryKey(nFeatureType.getTypeName(), nColumns));
|
||||
}
|
||||
} else {
|
||||
// JDBCState가 아닌 경우 (예: 다른 DataStore 구현체)
|
||||
// 혹은 기존의 ContentEntry가 JDBCState를 반환하지 않는 경우
|
||||
// 이 부분은 JDBC DataStore에 특화된 로직입니다.
|
||||
throw new IllegalArgumentException("Provided dataStore is not a JDBCDataStore or does not manage JDBCState correctly.");
|
||||
}
|
||||
|
||||
// dataStore.entries.put()와 같은 직접적인 필드 접근은 제거했습니다.
|
||||
// 대신, 스키마 변경이 ContentDataStore에 반영되도록 노력해야 합니다.
|
||||
// ContentDataStore는 FeatureType 변경을 내부적으로 처리하는 메커니즘을 가질 수 있습니다.
|
||||
// 이 코드가 제대로 작동하려면 DataStore의 refresh 또는 reload 메커니즘을 찾아야 합니다.
|
||||
// 아니면 새로운 DataStore 인스턴스를 생성해야 합니다.
|
||||
|
||||
// 여기서는 변경된 스키마로 새로운 FeatureSource를 얻으려는 시도입니다.
|
||||
// 하지만 기존 DataStore가 스키마 변경을 즉시 반영하지 않을 수 있습니다.
|
||||
return (ContentFeatureSource) dataStore.getFeatureSource(nFeatureType.getName()); // 변경된 이름으로 FeatureSource 요청
|
||||
}
|
||||
|
||||
/**
|
||||
* ShapefileDataStore의 FeatureType 스키마를 재구성합니다.
|
||||
* JDBCDataStore와 마찬가지로 내부 필드 접근은 피하고,
|
||||
* 스키마 변경을 ShapefileDataStore가 처리할 수 있도록 해야 합니다.
|
||||
* Shapefile의 특성상, 스키마 변경은 파일 자체의 변경을 의미하며,
|
||||
* 이는 DataStore 레벨에서 간단히 `setFeatureType`으로 처리하기 어렵습니다.
|
||||
* 일반적으로 Shapefile의 스키마 변경은 새 Shapefile을 생성하는 방식으로 이루어집니다.
|
||||
*
|
||||
* @param dataStore 재구성할 ShapefileDataStore
|
||||
* @return 재구성된 ShapefileDataStore
|
||||
* @throws IOException
|
||||
*/
|
||||
public static synchronized ShapefileDataStore refindShapefileDataStore(ShapefileDataStore dataStore) throws IOException {
|
||||
// ShapefileDataStore는 ContentDataStore를 상속하지만, JDBC와는 다르게 스키마를 다룹니다.
|
||||
// Shapefile은 파일 기반이므로, SimpleFeatureType 변경은 파일의 구조 변경을 의미합니다.
|
||||
// DataStore의 내부 상태를 직접 변경하는 것은 Shapefile에서는 매우 위험하고 잘못된 접근입니다.
|
||||
// 일반적으로 Shapefile의 스키마 변경은 새 Shapefile을 생성하고 데이터를 마이그레이션하는 방식으로 이루어집니다.
|
||||
|
||||
// 따라서 이 메서드는 GeoTools의 ShapefileDataStore의 동작 방식과 맞지 않습니다.
|
||||
// 만약 FeatureType의 속성 이름만 대문자로 바꾸는 것이 목적이라면,
|
||||
// FeatureCollection을 읽어서 새로운 FeatureCollection을 만들 때 속성 이름을 변경하거나,
|
||||
// ShapefileDataStore를 다시 로드하는 방식으로 접근해야 합니다.
|
||||
|
||||
// 기존 로직의 의도를 최대한 살려 보지만, 실제 작동을 보장하기 어렵습니다.
|
||||
SimpleFeatureSource cfs = dataStore.getFeatureSource(); // 기본 FeatureSource 가져오기
|
||||
SimpleFeatureType featureType = cfs.getSchema();
|
||||
|
||||
SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder();
|
||||
tBuilder.init(featureType);
|
||||
tBuilder.setName(featureType.getTypeName().toUpperCase());
|
||||
|
||||
AttributeTypeBuilder aBuilder = new AttributeTypeBuilder();
|
||||
for (AttributeDescriptor attr : featureType.getAttributeDescriptors()) {
|
||||
tBuilder.remove(attr.getLocalName());
|
||||
aBuilder.init(attr);
|
||||
for (Map.Entry<Object, Object> entry : attr.getUserData().entrySet()) { // Map.Entry 타입 명시
|
||||
aBuilder.addUserData(entry.getKey(), entry.getValue());
|
||||
}
|
||||
tBuilder.add(aBuilder.buildDescriptor(attr.getLocalName().toUpperCase()));
|
||||
}
|
||||
|
||||
SimpleFeatureType nFeatureType = tBuilder.buildFeatureType();
|
||||
nFeatureType.getUserData().putAll(featureType.getUserData());
|
||||
|
||||
// --- ShapefileDataStore의 내부 상태 직접 조작도 매우 위험합니다. ---
|
||||
// ShapefileDataStore는 ContentDataStore를 상속하지만,
|
||||
// 그 내부 ContentEntry/ContentState를 직접 조작하는 것은 지원되지 않습니다.
|
||||
// Shapefile은 read-only로 열려있을 경우 스키마를 변경할 수 없습니다.
|
||||
// write-access로 열었을 경우에도 setFeatureType으로 스키마를 변경하는 것은
|
||||
// 파일 자체의 스키마를 바꾸는 것이므로 매우 복잡한 과정이 필요합니다.
|
||||
|
||||
// 이 부분은 GeoTools의 `ShapefileDataStore`가 설계된 방식과 맞지 않으므로,
|
||||
// 이 코드가 제대로 작동하기 어렵습니다.
|
||||
// Shapefile의 스키마 변경은 일반적으로 새 Shapefile을 생성하고 데이터를 다시 쓰는 방식으로 이루어집니다.
|
||||
|
||||
// 주석 처리: 이 부분은 GeoTools의 안정적인 API를 사용하지 않으므로, 작동하지 않을 수 있습니다.
|
||||
/*
|
||||
ContentEntry entry = new ContentEntry(dataStore, nFeatureType.getName());
|
||||
ContentState state = entry.getState(Transaction.AUTO_COMMIT);
|
||||
state.setFeatureType(nFeatureType);
|
||||
dataStore.entries.put(entry.getName(), entry); // 이 줄은 컴파일 에러 발생 가능
|
||||
dataStore.entries.put(cfs.getEntry().getName(), entry); // 이 줄은 컴파일 에러 발생 가능
|
||||
*/
|
||||
|
||||
// 대신, 여기서는 새로운 FeatureType을 바탕으로 DataStore를 다시 로드하거나
|
||||
// 아예 새로운 Shapefile을 생성하는 것을 고려해야 합니다.
|
||||
// 이 메서드는 기존 ShapefileDataStore의 스키마를 "재정의"하는 것이므로,
|
||||
// 실제 Shapefile 파일의 스키마는 변경되지 않을 수 있습니다.
|
||||
// ShapefileDataStore는 스키마를 변경하는 API를 직접적으로 제공하지 않습니다.
|
||||
|
||||
System.err.println("Warning: refindShapefileDataStore attempts to modify internal state of ShapefileDataStore, which is generally not supported for schema changes. Consider creating a new Shapefile with the desired schema.");
|
||||
return dataStore; // 원본 DataStore를 반환 (실제 스키마 변경이 이루어지지 않을 수 있음)
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleFeatureSource의 CRS(좌표 참조 시스템)를 변경합니다.
|
||||
* ContentFeatureSource인 경우에만 내부 상태를 업데이트합니다.
|
||||
*
|
||||
* @param featureSource CRS를 변경할 SimpleFeatureSource
|
||||
* @param crs 새로운 CoordinateReferenceSystem
|
||||
* @return CRS가 변경된 SimpleFeatureSource (원본 객체 또는 새로운 객체일 수 있음)
|
||||
* @throws IOException
|
||||
*/
|
||||
public static synchronized SimpleFeatureSource changeCRSFeatureSource(SimpleFeatureSource featureSource, CoordinateReferenceSystem crs) throws IOException {
|
||||
if (featureSource instanceof ContentFeatureSource) {
|
||||
SimpleFeatureType currentType = featureSource.getSchema();
|
||||
// SimpleFeatureTypeBuilder.retype는 기존 FeatureType을 기반으로 새로운 CRS를 가진 FeatureType을 생성합니다.
|
||||
SimpleFeatureType newType = SimpleFeatureTypeBuilder.retype(currentType, crs);
|
||||
|
||||
// ContentFeatureSource의 Entry를 통해 내부 상태를 업데이트합니다.
|
||||
// 이 방식은 ContentDataStore의 구현에 따라 작동하거나 작동하지 않을 수 있습니다.
|
||||
// 특히 Shapefile의 경우, 파일 자체의 CRS가 변경되지 않는 이상 이 방식은 메타데이터만 변경할 수 있습니다.
|
||||
// 실제 데이터의 CRS 변환은 FeatureCollection을 통해 TransforingFeatureSource를 사용해야 합니다.
|
||||
((ContentFeatureSource) featureSource).getEntry().getState(Transaction.AUTO_COMMIT).setFeatureType(newType);
|
||||
} else {
|
||||
// ContentFeatureSource가 아닌 다른 SimpleFeatureSource 구현체인 경우
|
||||
// (예: PostGISDataStore의 SimpleFeatureSource 등)
|
||||
// 해당 DataStore의 특정 메서드를 통해 CRS를 변경해야 할 수 있습니다.
|
||||
// 또는 TransformingFeatureSource를 사용하여 CRS 변환을 수행하는 것이 더 일반적입니다.
|
||||
System.err.println("Warning: changeCRSFeatureSource is designed for ContentFeatureSource. For other types, consider using a TransformingFeatureSource or DataStore specific methods.");
|
||||
}
|
||||
return featureSource;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||
|
||||
public abstract interface CoordinateAccess extends CoordinateSequence
|
||||
{
|
||||
public abstract int getDimension();
|
||||
|
||||
public abstract int getNumAttributes();
|
||||
|
||||
public abstract double getOrdinate(int paramInt1, int paramInt2);
|
||||
|
||||
public abstract Object getAttribute(int paramInt1, int paramInt2);
|
||||
|
||||
public abstract void setOrdinate(int paramInt1, int paramInt2, double paramDouble);
|
||||
|
||||
public abstract void setAttribute(int paramInt1, int paramInt2, Object paramObject);
|
||||
|
||||
public abstract double[] toOrdinateArray(int paramInt);
|
||||
|
||||
public abstract Object[] toAttributeArray(int paramInt);
|
||||
|
||||
public abstract void setOrdinateArray(int paramInt, double[] paramArrayOfDouble);
|
||||
|
||||
public abstract void setAttributeArray(int paramInt, Object paramObject);
|
||||
|
||||
public abstract double[][] toOrdinateArrays();
|
||||
|
||||
public abstract Object[] toAttributeArrays();
|
||||
|
||||
public abstract void setCoordinateArrays(double[][] paramArrayOfDouble, Object[] paramArrayOfObject);
|
||||
|
||||
public abstract void setAt(int paramInt, double[] paramArrayOfDouble, Object[] paramArrayOfObject);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
|
||||
|
||||
public abstract interface CoordinateAccessFactory extends CoordinateSequenceFactory
|
||||
{
|
||||
public abstract CoordinateAccess create(double[][] paramArrayOfDouble, Object[] paramArrayOfObject);
|
||||
|
||||
public abstract int getDimension();
|
||||
|
||||
public abstract int getNumAttributes();
|
||||
}
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequences;
|
||||
import com.vividsolutions.jts.geom.PrecisionModel;
|
||||
import java.io.PrintStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class Coordinates
|
||||
{
|
||||
public static CoordinateSequence subList(CoordinateSequenceFactory factory, CoordinateSequence sequence, int fromIndex, int toIndex)
|
||||
{
|
||||
if ((fromIndex == 0) && (toIndex == sequence.size())) {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
if ((sequence instanceof List)) {
|
||||
List sublist = ((List)sequence).subList(fromIndex, toIndex);
|
||||
|
||||
if ((sublist instanceof CoordinateSequence)) {
|
||||
return (CoordinateSequence)sublist;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sequence instanceof CoordinateAccess)) {
|
||||
CoordinateAccess access = (CoordinateAccess)sequence;
|
||||
double[][] coordArray = access.toOrdinateArrays();
|
||||
Object[] attributeArray = access.toAttributeArrays();
|
||||
|
||||
double[][] subCoordArray = new double[access.getDimension()][];
|
||||
Object[][] subAttributeArray = new Object[access.getNumAttributes()][];
|
||||
|
||||
for (int i = 0; i < access.getDimension(); i++) {
|
||||
subCoordArray[i] = new OrdinateList(coordArray[i], 0, 1,
|
||||
fromIndex, toIndex).toDoubleArray();
|
||||
}
|
||||
|
||||
for (int i = 0; i < access.getNumAttributes(); i++) {
|
||||
subAttributeArray[i] = new AttributeList(attributeArray[i], 0,
|
||||
1, fromIndex, toIndex).toObjectArray();
|
||||
}
|
||||
|
||||
System.out.println("subCoordArray.length = " + subCoordArray.length);
|
||||
System.out.println("subCoordArray: ");
|
||||
System.out.print("X ");
|
||||
|
||||
for (int p = 0; p < subCoordArray[0].length; p++) {
|
||||
System.out.print(subCoordArray[0][p] + " ");
|
||||
}
|
||||
System.out.print("\nY ");
|
||||
|
||||
for (int p = 0; p < subCoordArray[1].length; p++) {
|
||||
System.out.print(subCoordArray[1][p] + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
System.out.println("subAttributeArray.length = " +
|
||||
subAttributeArray.length);
|
||||
System.out.println("subAttributeArray: ");
|
||||
System.out.print("Z ");
|
||||
|
||||
for (int p = 0; p < subAttributeArray[0].length; p++) {
|
||||
System.out.print(subAttributeArray[0][p] + " ");
|
||||
}
|
||||
System.out.print("\nT ");
|
||||
|
||||
for (int p = 0; p < subAttributeArray[1].length; p++) {
|
||||
System.out.print(subAttributeArray[1][p] + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
CoordinateAccess c = ((CoordinateAccessFactory)factory)
|
||||
.create(subCoordArray, subAttributeArray);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int size = toIndex - fromIndex;
|
||||
CoordinateSequence newSeq = factory.create(size, sequence.getDimension());
|
||||
//CoordinateSequences.copy(sequence, fromIndex, newSeq, 0, size);
|
||||
System.out.println("에러: CoordinateSequences.copy(sequence, fromIndex, newSeq, 0, size);");
|
||||
return newSeq;
|
||||
}
|
||||
|
||||
public static CoordinateSequence reverse(CoordinateSequenceFactory factory, CoordinateSequence sequence)
|
||||
{
|
||||
if ((sequence instanceof CoordinateAccess)) {
|
||||
CoordinateAccess access = (CoordinateAccess)sequence;
|
||||
double[][] coordArray = access.toOrdinateArrays();
|
||||
Object[] attributeArray = access.toAttributeArrays();
|
||||
|
||||
double[][] subCoordArray = new double[access.getDimension()][];
|
||||
Object[][] subAttributeArray = new Object[access.getNumAttributes()][];
|
||||
|
||||
for (int i = 0; i < access.getDimension(); i++) {
|
||||
subCoordArray[i] = new OrdinateList(coordArray[i], 0, 1,
|
||||
access.size() - 1, -1).toDoubleArray();
|
||||
}
|
||||
|
||||
for (int i = 0; i < access.getNumAttributes(); i++) {
|
||||
subAttributeArray[i] = new AttributeList(attributeArray[i], 0,
|
||||
1, access.size() - 1, -1).toObjectArray();
|
||||
}
|
||||
|
||||
CoordinateAccess c = ((CoordinateAccessFactory)factory)
|
||||
.create(subCoordArray, subAttributeArray);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
CoordinateSequence revSeq = factory.create(sequence);
|
||||
CoordinateSequences.reverse(revSeq);
|
||||
return revSeq;
|
||||
}
|
||||
|
||||
public static String toString(CoordinateSequence cs, int coordinate, NumberFormat nf)
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
append(buf, cs, coordinate, nf);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static void append(StringBuffer buf, CoordinateSequence cs, int coordinate, NumberFormat nf)
|
||||
{
|
||||
if ((cs instanceof CoordinateAccess)) {
|
||||
CoordinateAccess ca = (CoordinateAccess)cs;
|
||||
append(buf, ca, coordinate, LEN(ca), nf);
|
||||
} else {
|
||||
append(buf, cs, coordinate, LEN(cs), nf);
|
||||
}
|
||||
}
|
||||
|
||||
public static void append(StringBuffer buf, CoordinateSequence cs, int coordinate, int LEN, NumberFormat nf)
|
||||
{
|
||||
Coordinate c = cs.getCoordinate(coordinate);
|
||||
buf.append(nf.format(c.x));
|
||||
buf.append(" ");
|
||||
buf.append(nf.format(c.y));
|
||||
|
||||
if (LEN == 3) {
|
||||
buf.append(" ");
|
||||
buf.append(nf.format(c.z));
|
||||
}
|
||||
}
|
||||
|
||||
public static void append(StringBuffer buf, CoordinateAccess ca, int coordinate, int LEN, NumberFormat nf)
|
||||
{
|
||||
buf.append(nf.format(ca.getOrdinate(coordinate, 0)));
|
||||
|
||||
for (int i = 1; i < LEN; i++) {
|
||||
buf.append(" ");
|
||||
buf.append(nf.format(ca.getOrdinate(coordinate, i)));
|
||||
}
|
||||
}
|
||||
|
||||
public static int LEN(CoordinateSequence cs) {
|
||||
return D(cs) + L(cs);
|
||||
}
|
||||
|
||||
public static int D(CoordinateSequence cs) {
|
||||
if ((cs instanceof CoordinateAccess)) {
|
||||
return ((CoordinateAccess)cs).getDimension();
|
||||
}
|
||||
|
||||
if (cs.size() > 0) {
|
||||
return Double.isNaN(cs.getCoordinate(0).z) ? 2 : 3;
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static int L(CoordinateSequence cs) {
|
||||
if ((cs instanceof CoordinateAccess)) {
|
||||
return ((CoordinateAccess)cs).getNumAttributes();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static NumberFormat format(PrecisionModel pm) {
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setNaN("NaN");
|
||||
|
||||
DecimalFormat f = new DecimalFormat();
|
||||
f.setDecimalFormatSymbols(symbols);
|
||||
|
||||
if (pm == null) {
|
||||
f.setMaximumFractionDigits(0);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
f.setMinimumFractionDigits(0);
|
||||
f.setMaximumFractionDigits(pm.getMaximumSignificantDigits());
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
public static String toString(CoordinateSequence cs, PrecisionModel pm) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
append(buf, cs, format(pm));
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static void append(StringBuffer buf, CoordinateSequence cs, NumberFormat nf)
|
||||
{
|
||||
if ((cs instanceof CoordinateAccess)) {
|
||||
append(buf, (CoordinateAccess)cs, nf);
|
||||
} else {
|
||||
int LEN = LEN(cs);
|
||||
|
||||
if (cs.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
append(buf, cs, 0, LEN, nf);
|
||||
|
||||
if (cs.size() == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 1; i < cs.size(); i++) {
|
||||
buf.append(", ");
|
||||
append(buf, cs, i, LEN, nf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void append(StringBuffer buf, CoordinateAccess ca, NumberFormat nf)
|
||||
{
|
||||
int LEN = LEN(ca);
|
||||
|
||||
if (ca.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
append(buf, ca, 0, LEN, nf);
|
||||
|
||||
if (ca.size() == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 1; i < ca.size(); i++) {
|
||||
buf.append(", ");
|
||||
append(buf, ca, i, LEN, nf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.KeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.geotools.data.Base64;
|
||||
|
||||
public class EncryptUtil
|
||||
{
|
||||
private static final String characterEncoding = "UTF-8";
|
||||
private static final String cipherTransformation = "AES/CBC/PKCS5Padding";
|
||||
private static final String aesEncryptionAlgorithm = "AES";
|
||||
public static final String ENCRYPTIONKEY = "wldhxn";
|
||||
|
||||
private static byte[] decrypt(byte[] cipherText, byte[] key, byte[] initialVector)
|
||||
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
|
||||
{
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
SecretKeySpec secretKeySpecy = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVector);
|
||||
cipher.init(2, secretKeySpecy, ivParameterSpec);
|
||||
cipherText = cipher.doFinal(cipherText);
|
||||
return cipherText;
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] plainText, byte[] key, byte[] initialVector) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
|
||||
{
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVector);
|
||||
cipher.init(1, secretKeySpec, ivParameterSpec);
|
||||
plainText = cipher.doFinal(plainText);
|
||||
return plainText;
|
||||
}
|
||||
|
||||
private static byte[] getKeyBytes(String key) throws UnsupportedEncodingException {
|
||||
byte[] keyBytes = new byte[16];
|
||||
byte[] parameterKeyBytes = key.getBytes("UTF-8");
|
||||
System.arraycopy(parameterKeyBytes, 0, keyBytes, 0, Math.min(parameterKeyBytes.length, keyBytes.length));
|
||||
return keyBytes;
|
||||
}
|
||||
|
||||
public static String encrypt(String plainText, String key)
|
||||
throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
|
||||
{
|
||||
byte[] plainTextbytes = plainText.getBytes("UTF-8");
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
return Base64.encodeBytes(encrypt(plainTextbytes, keyBytes, keyBytes));
|
||||
}
|
||||
|
||||
public static String decrypt(String encryptedText, String key)
|
||||
throws KeyException, GeneralSecurityException, GeneralSecurityException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, IOException
|
||||
{
|
||||
byte[] cipheredBytes = Base64.decode(encryptedText);
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
return new String(decrypt(cipheredBytes, keyBytes, keyBytes), "UTF-8");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.geotools.data.FeatureSource;
|
||||
import org.geotools.map.FeatureLayer;
|
||||
import org.geotools.styling.Style;
|
||||
|
||||
public class ExFeatureLayer
|
||||
extends FeatureLayer {
|
||||
public ExFeatureLayer(FeatureSource featureSource, Style style) {
|
||||
super(featureSource, style);
|
||||
}
|
||||
|
||||
public boolean isWrapTileTextLayer() {
|
||||
return ((MapStyle)this.getStyle()).isWrapTileTextStyle();
|
||||
}
|
||||
|
||||
public double getWrapTileText() {
|
||||
return ((MapStyle)this.getStyle()).getWrapTileText();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.DirectLayer;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.map.MapViewport;
|
||||
import org.geotools.referencing.CRS;
|
||||
|
||||
public class ExO2ImgLayer extends DirectLayer
|
||||
{
|
||||
private O2ImgLayer imgLayer;
|
||||
private ReferencedEnvelope WMS_BBOX;
|
||||
private int WMS_WIDTH;
|
||||
private int WMS_HEIGHT;
|
||||
|
||||
public ExO2ImgLayer(O2ImgLayer layer, AVList params)
|
||||
throws Exception
|
||||
{
|
||||
this.imgLayer = layer;
|
||||
|
||||
this.WMS_BBOX = ((ReferencedEnvelope)params.getValue("request.wms.bbox"));
|
||||
|
||||
if (!CRS.equalsIgnoreMetadata(
|
||||
layer.getCRS(),
|
||||
this.WMS_BBOX.getCoordinateReferenceSystem())) {
|
||||
this.WMS_BBOX = this.WMS_BBOX.transform(layer.getCRS(), true);
|
||||
}
|
||||
|
||||
this.WMS_WIDTH = params.getIntegerValue("request.wms.width").intValue();
|
||||
this.WMS_HEIGHT = params.getIntegerValue("request.wms.height").intValue();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBounds()
|
||||
{
|
||||
return this.imgLayer.getBBox();
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics, MapContent map, MapViewport viewport)
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedImage img = O2LayerUtil.getMap(this.imgLayer.getLevelSet(), this.WMS_BBOX, this.WMS_WIDTH, this.WMS_HEIGHT);
|
||||
graphics.drawImage(img, null, 0, 0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[RENDER]", "Fail to render O2ImgLayer :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.geotools.data.ows.HTTPResponse;
|
||||
import org.geotools.data.ows.SimpleHttpClient;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.DirectLayer;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.map.MapViewport;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
|
||||
public class ExWMSLayer extends DirectLayer
|
||||
{
|
||||
final String WMS_LAYERS;
|
||||
ReferencedEnvelope WMS_BBOX;
|
||||
int WMS_WIDTH;
|
||||
int WMS_HEIGHT;
|
||||
final String WMS_FORMAT;
|
||||
final String WMS_SERVICE;
|
||||
final String WMS_VERSION;
|
||||
final String WMS_REQUEST;
|
||||
final boolean WMS_TRANSPARENT;
|
||||
final Color WMS_BGCOLOR;
|
||||
final String WMS_STYLES;
|
||||
final StyledLayerDescriptor WMS_SLD;
|
||||
private final URL layerURL;
|
||||
private final ReferencedEnvelope layerBounds;
|
||||
|
||||
public ExWMSLayer(LinkLayer layer, AVList params)
|
||||
throws Exception
|
||||
{
|
||||
if ((layer == null) || (params == null)) {
|
||||
throw new IllegalArgumentException("WMS request parameter is null.");
|
||||
}
|
||||
|
||||
this.layerBounds = layer.getBBox();
|
||||
this.layerURL = layer.getServiceURL();
|
||||
this.WMS_LAYERS = layer.getServiceLayerNames();
|
||||
|
||||
this.WMS_BBOX = ((ReferencedEnvelope)params.getValue("request.wms.bbox"));
|
||||
|
||||
if (!CRS.equalsIgnoreMetadata(this.layerBounds.getCoordinateReferenceSystem(),
|
||||
this.WMS_BBOX.getCoordinateReferenceSystem())) {
|
||||
this.WMS_BBOX = this.WMS_BBOX.transform(this.layerBounds.getCoordinateReferenceSystem(), true);
|
||||
}
|
||||
this.WMS_WIDTH = params.getIntegerValue("request.wms.width").intValue();
|
||||
this.WMS_HEIGHT = params.getIntegerValue("request.wms.height").intValue();
|
||||
|
||||
this.WMS_SERVICE = params.getStringValue("request.wms.service", "WMS");
|
||||
this.WMS_FORMAT = params.getStringValue("request.wms.format", "image/jpeg");
|
||||
this.WMS_VERSION = params.getStringValue("request.wms.version", "1.3.0");
|
||||
this.WMS_REQUEST = params.getStringValue("request.wms.request", "GetMap");
|
||||
this.WMS_TRANSPARENT = params.getBooleanValue("request.wms.transparent", Boolean.valueOf(false)).booleanValue();
|
||||
this.WMS_BGCOLOR = params.getColorValue("request.wms.bgcolor", Color.WHITE);
|
||||
|
||||
if (ServerUtil.isNullString(params.getStringValue("request.wms.styles")))
|
||||
{
|
||||
String[] layerNames = this.WMS_LAYERS.split(",");
|
||||
if (layerNames.length == 1) {
|
||||
this.WMS_STYLES = "";
|
||||
} else {
|
||||
String styles = "";
|
||||
for (int i = 1; i < layerNames.length; i++) {
|
||||
styles = styles.concat(",");
|
||||
}
|
||||
this.WMS_STYLES = styles;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String styleStr = params.getStringValue("request.wms.styles");
|
||||
|
||||
String[] layerNames = this.WMS_LAYERS.split(",");
|
||||
if (layerNames.length == 1) {
|
||||
this.WMS_STYLES = styleStr;
|
||||
} else {
|
||||
String styles = styleStr;
|
||||
for (int i = 1; i < layerNames.length; i++) {
|
||||
styles = styles.concat(",");
|
||||
styles = styles.concat(styleStr);
|
||||
}
|
||||
this.WMS_STYLES = styles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.WMS_SLD = ((StyledLayerDescriptor)params.getValue("request.wms.sld"));
|
||||
}
|
||||
|
||||
private URL getRequest() throws MalformedURLException
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append("?");
|
||||
sb.append("SERVICE=").append(this.WMS_SERVICE).append("&");
|
||||
sb.append("VERSION=").append(this.WMS_VERSION).append("&");
|
||||
sb.append("REQUEST=").append(this.WMS_REQUEST).append("&");
|
||||
|
||||
sb.append("LAYERS=").append(this.WMS_LAYERS).append("&");
|
||||
sb.append("STYLES=").append(this.WMS_STYLES).append("&");
|
||||
|
||||
if (this.WMS_VERSION.compareTo("1.3.0") >= 0)
|
||||
sb.append("CRS=").append(this.WMS_BBOX.getCoordinateReferenceSystem().getIdentifiers().toArray()[0]).append("&");
|
||||
else {
|
||||
sb.append("SRS=").append(this.WMS_BBOX.getCoordinateReferenceSystem().getIdentifiers().toArray()[0]).append("&");
|
||||
}
|
||||
|
||||
sb.append("BBOX=").append(this.WMS_BBOX.getMinX()).append(",").append(this.WMS_BBOX.getMinY()).append(",")
|
||||
.append(this.WMS_BBOX.getMaxX()).append(",").append(this.WMS_BBOX.getMaxY()).append("&");
|
||||
|
||||
sb.append("WIDTH=").append(this.WMS_WIDTH).append("&");
|
||||
sb.append("HEIGHT=").append(this.WMS_HEIGHT).append("&");
|
||||
|
||||
sb.append("FORMAT=").append(this.WMS_FORMAT).append("&");
|
||||
sb.append("TRANSPARENT=").append(this.WMS_TRANSPARENT).append("&");
|
||||
|
||||
sb.append("BGCOLOR=").append(ServerUtil.getHexFromColor(this.WMS_BGCOLOR));
|
||||
|
||||
return new URL(this.layerURL, sb.toString());
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics, MapContent map, MapViewport viewport)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = getRequest();
|
||||
|
||||
SimpleHttpClient client = new SimpleHttpClient();
|
||||
HTTPResponse reponse = client.get(url);
|
||||
|
||||
BufferedImage image = ImageIO.read(reponse.getResponseStream());
|
||||
|
||||
graphics.drawImage(image, 0, 0, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[RENDER]",
|
||||
"Fail to render WMSLayer :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBounds()
|
||||
{
|
||||
return this.layerBounds;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import org.geotools.styling.RasterSymbolizerImpl;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.style.Description;
|
||||
import org.opengis.style.GraphicLegend;
|
||||
|
||||
public class ExtractRasterStyleVisitor extends DuplicatingStyleVisitor
|
||||
{
|
||||
public void visit(Rule rule)
|
||||
{
|
||||
Rule copy = this.sf.createRule();
|
||||
|
||||
Symbolizer[] symsCopy = rule.getSymbolizers();
|
||||
for (int i = 0; i < symsCopy.length; i++)
|
||||
{
|
||||
if ((symsCopy[i] instanceof RasterSymbolizerImpl)) {
|
||||
copy.symbolizers().add(copy(symsCopy[i]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Filter filterCopy = null;
|
||||
if (rule.getFilter() != null) {
|
||||
Filter filter = rule.getFilter();
|
||||
filterCopy = copy(filter);
|
||||
}
|
||||
copy.setFilter(filterCopy);
|
||||
|
||||
copy.setElseFilter(rule.isElseFilter());
|
||||
|
||||
copy.setMaxScaleDenominator(rule.getMaxScaleDenominator());
|
||||
copy.setMinScaleDenominator(rule.getMinScaleDenominator());
|
||||
|
||||
GraphicLegend legendCopy = rule.getLegend();
|
||||
if (legendCopy != null) {
|
||||
copy.setLegend(legendCopy);
|
||||
}
|
||||
|
||||
Description descCopy = rule.getDescription();
|
||||
copy.setDescription(copy(descCopy));
|
||||
|
||||
copy.setName(rule.getName());
|
||||
|
||||
if ((this.STRICT) && (!copy.equals(rule))) {
|
||||
throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
|
||||
}
|
||||
this.pages.push(copy);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,342 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class FeatureLayer
|
||||
extends Layer {
|
||||
private final String sourceName;
|
||||
private ReferencedEnvelope bbox;
|
||||
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap();
|
||||
private Style currentStyle;
|
||||
private ConcurrentHashMap<String, Style> renderStyles = new ConcurrentHashMap();
|
||||
|
||||
public FeatureLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
StyledLayerDescriptor sld;
|
||||
String sVal = params.getStringValue("conf.service.ref.source");
|
||||
this.sourceName = sVal = sVal.trim().toUpperCase();
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||
this.bbox = featureSource.getBounds();
|
||||
if (params.getValue("conf.service.sld") == null) {
|
||||
Style style = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||
this.setCurrentStyle(style);
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
} else {
|
||||
sld = (StyledLayerDescriptor)params.getValue("conf.service.sld");
|
||||
this.initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Set Style From DB :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
sld = StyleMngr.readServiceSLD((String)this.getName());
|
||||
if (sld != null) {
|
||||
this.initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Override Style From SLD FILE :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
}
|
||||
try {
|
||||
if (this.isUseCache().booleanValue()) {
|
||||
O2DSMngr.putMemoryFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (Filter)Filter.INCLUDE);
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Now use memery DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Fail to make memery DataStore. Now use common DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reloadServiceStyle() {
|
||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD((String)this.getName());
|
||||
if (sld != null) {
|
||||
this.initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Reload Style From SLD FILE :: [Map:" + this.getMapName() + "/Layer:" + this.getName() + "]");
|
||||
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + this.getMapName() + "/Layer:" + this.getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write) {
|
||||
Style defaultStyle = null;
|
||||
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||
for (StyledLayer styledLayer : sld.layers()) {
|
||||
if (!ServerUtil.isNullString((String)styledLayer.getName()) && !styledLayer.getName().equalsIgnoreCase(this.getName())) continue;
|
||||
Iterator<Style> iterStyle = this.getStyleIterator(styledLayer);
|
||||
while (iterStyle.hasNext()) {
|
||||
Style style = iterStyle.next();
|
||||
if (style instanceof NamedStyle) continue;
|
||||
if (ServerUtil.isNullString((String)style.getName())) {
|
||||
style.setName(this.getName());
|
||||
} else {
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
}
|
||||
tempStore.put(style.getName(), style);
|
||||
if (defaultStyle != null && defaultStyle.getName().equals(style.getName())) {
|
||||
defaultStyle = null;
|
||||
}
|
||||
if (!style.isDefault()) continue;
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
continue;
|
||||
}
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
}
|
||||
if (defaultStyle == null) {
|
||||
if (this.getCurrentStyle() == null) {
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||
} else {
|
||||
defaultStyle = (Style)tempStore.get(this.getName());
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = (Style)tempStore.values().iterator().next();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
defaultStyle = (Style)tempStore.get(this.getCurrentStyle().getName());
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = this.getCurrentStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setCurrentStyle(defaultStyle);
|
||||
this.styleStore.putAll(tempStore);
|
||||
if (write) {
|
||||
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(StyledLayer styledLayer, boolean write) {
|
||||
Style defaultStyle = null;
|
||||
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||
if (!ServerUtil.isNullString((String)styledLayer.getName()) && !styledLayer.getName().equalsIgnoreCase(this.getName())) {
|
||||
return;
|
||||
}
|
||||
Iterator<Style> iterStyle = this.getStyleIterator(styledLayer);
|
||||
while (iterStyle.hasNext()) {
|
||||
Style style = iterStyle.next();
|
||||
if (style instanceof NamedStyle) continue;
|
||||
if (ServerUtil.isNullString((String)style.getName())) {
|
||||
style.setName(this.getName());
|
||||
} else {
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
}
|
||||
tempStore.put(style.getName(), style);
|
||||
if (defaultStyle != null && defaultStyle.getName().equals(style.getName())) {
|
||||
defaultStyle = null;
|
||||
}
|
||||
if (!style.isDefault()) continue;
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
continue;
|
||||
}
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
if (defaultStyle == null) {
|
||||
if (this.getCurrentStyle() == null) {
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||
} else {
|
||||
defaultStyle = (Style)tempStore.get(this.getName());
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = (Style)tempStore.values().iterator().next();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
defaultStyle = (Style)tempStore.get(this.getCurrentStyle().getName());
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = this.getCurrentStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setCurrentStyle(defaultStyle);
|
||||
this.styleStore.putAll(tempStore);
|
||||
if (write) {
|
||||
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(Style style, boolean write) {
|
||||
if (style == null || style instanceof NamedStyle) {
|
||||
return;
|
||||
}
|
||||
if (ServerUtil.isNullString((String)style.getName())) {
|
||||
style.setName(this.getName());
|
||||
} else {
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
}
|
||||
this.styleStore.put(style.getName(), style);
|
||||
if (style.isDefault() || style.getName().equalsIgnoreCase(this.getCurrentStyle().getName())) {
|
||||
this.setCurrentStyle(style);
|
||||
}
|
||||
if (write) {
|
||||
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||
}
|
||||
}
|
||||
|
||||
private Iterator<Style> getStyleIterator(StyledLayer layer) {
|
||||
if (layer instanceof NamedLayer) {
|
||||
return ((NamedLayer)layer).styles().iterator();
|
||||
}
|
||||
return ((UserLayer)layer).userStyles().iterator();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return super.getServerName().toUpperCase();
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return this.sourceName;
|
||||
}
|
||||
|
||||
public void updateCRS() {
|
||||
super.updateCRS();
|
||||
try {
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||
if (!CRS.equalsIgnoreMetadata((Object)this.getCRS(), (Object)((SimpleFeatureType)featureSource.getSchema()).getCoordinateReferenceSystem())) {
|
||||
featureSource = O2DSMngr.changeCRSFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (CoordinateReferenceSystem)this.getCRS());
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for FeatureSouce [" + this.getSourceName() + "]");
|
||||
this.updateBBox();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Fail to update CRS for FeatureSouce [" + this.getSourceName() + "] :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBBox() {
|
||||
try {
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||
this.bbox = featureSource.getBounds();
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update BBOX for Layer [" + this.getName() + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Fail to update BBOX for Layer [" + this.getName() + "] :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Style getRenderStyle(String styleName) {
|
||||
if (ServerUtil.isNullString((String)styleName)) {
|
||||
styleName = "DEFAULT";
|
||||
}
|
||||
if (this.renderStyles.containsKey(styleName = styleName.trim().toUpperCase())) {
|
||||
return this.renderStyles.get(styleName);
|
||||
}
|
||||
Style style = this.getStyle(styleName);
|
||||
if (style == null) {
|
||||
style = this.getCurrentStyle();
|
||||
}
|
||||
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
||||
style.accept((StyleVisitor)sVisitor);
|
||||
style = (Style)sVisitor.getCopy();
|
||||
this.renderStyles.put(styleName, style);
|
||||
return style;
|
||||
}
|
||||
|
||||
public Style getStyle(String styleName) {
|
||||
if (!ServerUtil.isNullString((String)styleName)) {
|
||||
return this.styleStore.get(styleName.trim().toUpperCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isContainStyle(String styleName) {
|
||||
return !ServerUtil.isNullString((String)styleName) && this.styleStore.containsKey(styleName.trim().toUpperCase());
|
||||
}
|
||||
|
||||
public StyledLayerDescriptor getStyleSLD(String[] styleNames) {
|
||||
if (styleNames == null || styleNames.length == 0) {
|
||||
return this.getStyleSLD();
|
||||
}
|
||||
ArrayList<Style> styles = new ArrayList<Style>();
|
||||
String[] stringArray = styleNames;
|
||||
int n = styleNames.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
String styleName = stringArray[n2];
|
||||
if (!ServerUtil.isNullString((String)styleName) && this.styleStore.containsKey(styleName = styleName.trim().toUpperCase())) {
|
||||
styles.add(this.styleStore.get(styleName));
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||
layer.setName(this.getName());
|
||||
layer.styles().addAll(styles);
|
||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||
sld.addStyledLayer((StyledLayer)layer);
|
||||
sld.setName(this.getName());
|
||||
return sld;
|
||||
}
|
||||
|
||||
public StyledLayerDescriptor getStyleSLD() {
|
||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||
layer.setName(this.getName());
|
||||
layer.styles().addAll(this.styleStore.values());
|
||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||
sld.addStyledLayer((StyledLayer)layer);
|
||||
sld.setName(this.getName());
|
||||
return sld;
|
||||
}
|
||||
|
||||
public Style getCurrentStyle() {
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
private Style setCurrentStyle(Style style) {
|
||||
this.renderStyles.remove(style.getName().trim().toUpperCase());
|
||||
if (this.currentStyle != null) {
|
||||
this.currentStyle.setDefault(false);
|
||||
}
|
||||
this.currentStyle = style;
|
||||
this.currentStyle.setDefault(true);
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
public void clearStyle(String styleName, boolean write) {
|
||||
if (ServerUtil.isNullString((String)styleName)) {
|
||||
return;
|
||||
}
|
||||
if (this.styleStore.remove(styleName = styleName.trim().toUpperCase()) == null) {
|
||||
return;
|
||||
}
|
||||
if (this.getCurrentStyle().getName().equalsIgnoreCase(styleName)) {
|
||||
Style style = this.getStyle(this.getName());
|
||||
if (style == null) {
|
||||
style = this.styleStore.isEmpty() ? StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName()) : this.styleStore.values().iterator().next();
|
||||
}
|
||||
this.setCurrentStyle(style);
|
||||
}
|
||||
if (write) {
|
||||
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllStyle(boolean write) {
|
||||
if (this.styleStore.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
this.styleStore.clear();
|
||||
this.renderStyles.clear();
|
||||
this.setCurrentStyle(StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName()));
|
||||
if (write) {
|
||||
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,61 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
public class FieldInfo {
|
||||
private FieldSQL.FieldType type;
|
||||
private String name;
|
||||
private Integer precision;
|
||||
private Integer scale;
|
||||
private boolean primaryKey;
|
||||
private boolean notNull;
|
||||
|
||||
public FieldInfo(String name, FieldSQL.FieldType type, Integer precision, Integer scale, boolean primaryKey, boolean notNull) {
|
||||
this.type = type;
|
||||
this.name = name.toUpperCase();
|
||||
this.precision = precision;
|
||||
this.scale = scale;
|
||||
this.primaryKey = primaryKey;
|
||||
this.notNull = notNull;
|
||||
}
|
||||
|
||||
public FieldInfo(String name, FieldSQL.FieldType type, Integer precision, boolean primaryKey, boolean notNull) {
|
||||
this.type = type;
|
||||
this.name = name.toUpperCase();
|
||||
this.precision = precision;
|
||||
this.scale = null;
|
||||
this.primaryKey = primaryKey;
|
||||
this.notNull = notNull;
|
||||
}
|
||||
|
||||
public FieldInfo(String name, FieldSQL.FieldType type, boolean primaryKey, boolean notNull) {
|
||||
this.type = type;
|
||||
this.name = name.toUpperCase();
|
||||
this.precision = null;
|
||||
this.scale = null;
|
||||
this.primaryKey = primaryKey;
|
||||
this.notNull = notNull;
|
||||
}
|
||||
|
||||
public boolean isNotNull() {
|
||||
return this.notNull;
|
||||
}
|
||||
|
||||
public boolean isPrimaryKey() {
|
||||
return this.primaryKey;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public FieldSQL.FieldType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Integer getScale() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public Integer getPrecision() {
|
||||
return this.precision;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FieldSQL
|
||||
{
|
||||
private final O2DSFactory.DBMSType dbType;
|
||||
private final Map<FieldType, String> dbFields;
|
||||
private final boolean isUnsignedScale;
|
||||
|
||||
public FieldSQL(O2DSFactory.DBMSType dbmsType, HashMap<FieldType, String> fields, boolean unsignedScale)
|
||||
{
|
||||
this.dbType = dbmsType;
|
||||
this.dbFields = Collections.unmodifiableMap(fields);
|
||||
this.isUnsignedScale = unsignedScale;
|
||||
}
|
||||
|
||||
public O2DSFactory.DBMSType getDBType() {
|
||||
return this.dbType;
|
||||
}
|
||||
|
||||
public String getGeomFieldType(Class geom, String srid) throws Exception
|
||||
{
|
||||
String sql = (String)this.dbFields.get(FieldType.GEOMETRY);
|
||||
if (sql == null) {
|
||||
sql = FieldType.GEOMETRY.fieldSql;
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
public String getFieldType(Class clazz, int precision, int scale) throws Exception
|
||||
{
|
||||
FieldType type = FieldType.UNKNOWN;
|
||||
for (FieldType value : FieldType.values()) {
|
||||
for (Class cls : value.fieldTypes) {
|
||||
if (cls.isAssignableFrom(clazz)) {
|
||||
return getFieldType(value, precision, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getFieldType(type, precision, scale);
|
||||
}
|
||||
|
||||
public String getFieldType(FieldType fType, int precision, int scale)
|
||||
throws Exception
|
||||
{
|
||||
String sql = (String)this.dbFields.get(fType);
|
||||
if (sql == null) {
|
||||
sql = fType.fieldSql;
|
||||
}
|
||||
|
||||
if ((fType == FieldType.GEOMETRY) ||
|
||||
(fType == FieldType.BOOLEAN) ||
|
||||
(fType == FieldType.DATE) ||
|
||||
(fType == FieldType.BLOB) ||
|
||||
(fType == FieldType.UNKNOWN)) {
|
||||
return sql;
|
||||
}
|
||||
|
||||
if (precision < 0) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: precision is < 0 for " + fType);
|
||||
throw new SQLException("getFieldType :: precision is < 0 for " + fType);
|
||||
}
|
||||
if ((precision == 0) && (scale == 0)) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: precision and scale is 0 for " + fType);
|
||||
throw new SQLException("getFieldType :: precision and scale is 0 for " + fType);
|
||||
}
|
||||
if (scale < 0)
|
||||
{
|
||||
if (this.isUnsignedScale) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: scale is must use unsigned value for " + fType);
|
||||
throw new SQLException("getFieldType :: scale is must use unsigned value for " + fType);
|
||||
}
|
||||
if (precision + scale <= 0) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||
throw new SQLException("getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||
}
|
||||
}
|
||||
else if (precision - scale < 0) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||
throw new SQLException("getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer(sql);
|
||||
if (fType == FieldType.CHARACTER) {
|
||||
if (precision == 0) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"getFieldType :: precision is 0 for " + fType);
|
||||
throw new SQLException("getFieldType :: precision is 0 for " + fType);
|
||||
}
|
||||
sb.append("(").append(precision).append(")");
|
||||
}
|
||||
else {
|
||||
sb.append("(");
|
||||
sb.append(precision).append(",").append(scale);
|
||||
sb.append(")");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static enum FieldType
|
||||
{
|
||||
GEOMETRY("GEOMETRY", new Class[] { com.vividsolutions.jts.geom.Geometry.class, org.opengis.geometry.Geometry.class }),
|
||||
CHARACTER("VARCHAR", new Class[] { String.class }),
|
||||
NUMERIC("NUMBER", new Class[] { Short.class, Integer.class, Long.class, Float.class, Double.class }),
|
||||
BOOLEAN("CHAR(1)", new Class[] { Boolean.class }),
|
||||
DATE("DATE", new Class[] { Date.class }),
|
||||
BLOB("BLOB", new Class[] { java.lang.Byte.class }),
|
||||
UNKNOWN("VARCHAR", new Class[] { Object.class });
|
||||
|
||||
private final Class[] fieldTypes;
|
||||
private final String fieldSql;
|
||||
|
||||
private FieldType(String sql, Class[] types) { this.fieldSql = sql;
|
||||
this.fieldTypes = types;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class FileComparator
|
||||
implements Comparator<File>
|
||||
{
|
||||
public int compare(File f1, File f2)
|
||||
{
|
||||
if (f1.lastModified() > f2.lastModified()) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
public class GWaveLayerInfo {
|
||||
private boolean activate = false;
|
||||
private String layerName;
|
||||
private String layerSource;
|
||||
private String desc;
|
||||
|
||||
public boolean isActivate() {
|
||||
return this.activate;
|
||||
}
|
||||
|
||||
public String getLayerName() {
|
||||
return this.layerName;
|
||||
}
|
||||
|
||||
public String getLayerSource() {
|
||||
return this.layerSource;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public void setLayerName(String name) {
|
||||
if (ServerUtil.isNullString((String)name)) {
|
||||
this.layerName = null;
|
||||
}
|
||||
this.layerName = name.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public void setLayerSource(String source) {
|
||||
if (ServerUtil.isNullString((String)source)) {
|
||||
this.layerSource = null;
|
||||
}
|
||||
this.layerSource = source.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public void setActivate(String actiStr) {
|
||||
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
if (!this.activate) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.activate] is False");
|
||||
return false;
|
||||
}
|
||||
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.name] is Empty");
|
||||
return false;
|
||||
}
|
||||
if (ServerUtil.isNullString((String)this.layerSource)) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.source] is Empty");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,479 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
import com.geowave.drvier.GWDriver;
|
||||
import com.geowave.vectordrvier.GWVectorDriver;
|
||||
|
||||
public class GWaveStoreMngr
|
||||
{
|
||||
private static ConcurrentHashMap<String, GeoWaveDataStore> dataStores = new ConcurrentHashMap();
|
||||
private static ConcurrentHashMap<String, GeoWaveDataStore> dirtyDataStores;
|
||||
|
||||
public static synchronized void initLayers()
|
||||
{
|
||||
dataStores = new ConcurrentHashMap();
|
||||
int count = 0;
|
||||
synchronized (dataStores)
|
||||
{
|
||||
try
|
||||
{
|
||||
File dir = ServerContext.getPluginsFolder();
|
||||
String fileName = ServerContext.getMap().getName() + LayerFactory.LayerType.GEOWAVE.getPrefix();
|
||||
|
||||
File confFile = ServerUtil.findFile(dir, fileName);
|
||||
|
||||
if (confFile == null) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"Skip create GeoWaveLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
LogMngr.getInstance().logDebug("[GWAVE]",
|
||||
"[" + confFile.getName() + "] Now create GeoWaveLayer from this configuration");
|
||||
|
||||
GeoWaveDataStore dataStore = parseGWaveServerInfo(confFile);
|
||||
if (dataStore == null) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + confFile.getName() + "] Fail to create GeoWaveLayer :: GWaveDataStore is not available");
|
||||
return;
|
||||
}
|
||||
dataStores.put(dataStore.getStoreName(), dataStore);
|
||||
|
||||
ArrayList<GWaveLayerInfo> layerInfoList = parseGWaveLayerInfo(confFile);
|
||||
if ((layerInfoList == null) || (layerInfoList.isEmpty())) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + confFile.getName() + "] Fail to create GeoWaveLayer :: GeoWaveLayer size is ZERO[0] from this configuration");
|
||||
return;
|
||||
}
|
||||
|
||||
for (GWaveLayerInfo info : layerInfoList)
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[GWAVE]",
|
||||
"[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this GeoWaveLayer");
|
||||
try
|
||||
{
|
||||
addLayer(dataStore.getStoreName(), info.getLayerName(), info.getLayerSource(), info.getDesc());
|
||||
|
||||
count++;
|
||||
|
||||
LogMngr.getInstance().logInfo("[GWAVE]",
|
||||
"[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " +
|
||||
"[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " +
|
||||
"[RefServer:" + LayerFactory.LayerType.GEOWAVE.getType() + "/RefSource:" + info.getLayerSource() + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||
}
|
||||
|
||||
LogMngr.getInstance().logDebug("[GWAVE]", "");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[GWAVE]", "Fail to create GeoWaveLayer :: " + e);
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"Create GeoWaveLayer Fail :: GeoWaveLayer size is ZERO[0]");
|
||||
else
|
||||
LogMngr.getInstance().logInfo("[GWAVE]",
|
||||
"Create GeoWaveLayer Success :: GeoWaveLayer Count is [" + count + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public static FeatureLayer addLayer(String storeName, String layerName, String layerSource, String desc)
|
||||
throws Exception
|
||||
{
|
||||
GeoWaveDataStore store = getDataStore(storeName);
|
||||
if (store == null) {
|
||||
throw new IOException("GeoWaveLayer DataStore is not exist [" + storeName + "]");
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(layerName))
|
||||
throw new IOException("GeoWaveLayer LayerName is null");
|
||||
if (ServerContext.getMap().getServiceLayerSet().isExistLayer(layerName)) {
|
||||
throw new IOException("GeoWaveLayer LayerName [" + layerName + "] is already exist");
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(layerSource)) {
|
||||
throw new IOException("GeoWaveLayer LayerSource is null");
|
||||
}
|
||||
layerSource = layerSource.trim().toUpperCase();
|
||||
|
||||
List layers = Arrays.asList(store.getTypeNames());
|
||||
if (!layers.contains(layerSource)) {
|
||||
throw new IOException("GeoWaveLayer LayerSource [" + layerSource + "] is not exist in this GeoWaveDataStore [" + storeName + "]");
|
||||
}
|
||||
|
||||
GWVectorDriver gwvDriver = store.getGWVDriver();
|
||||
try
|
||||
{
|
||||
gwvDriver.open_layer(layerSource);
|
||||
CoordinateReferenceSystem crs = gwvDriver.getVectorMeta(layerSource).getCRS();
|
||||
if (crs == null) {
|
||||
crs = CRSMngr.getCRS(Integer.valueOf(4326));
|
||||
}
|
||||
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", layerName);
|
||||
params.setValue("conf.service.ref.server", storeName);
|
||||
params.setValue("conf.service.ref.source", layerSource);
|
||||
params.setValue("conf.service.ref.crs", crs);
|
||||
params.setValue("conf.service.sld", null);
|
||||
params.setValue("conf.service.use.cache", Boolean.valueOf(false));
|
||||
params.setValue("conf.service.last.update", null);
|
||||
params.setValue("conf.service.description", desc);
|
||||
|
||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.GEOWAVE, params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
|
||||
return (FeatureLayer)layer;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gwvDriver != null)
|
||||
try {
|
||||
gwvDriver.close();
|
||||
}
|
||||
catch (IOException localIOException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<GWaveLayerInfo> parseGWaveLayerInfo(File conf)
|
||||
{
|
||||
if (!conf.exists()) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Create GeoWaveLayer Fail :: GeoWaveLayer configuration is not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList layerInfoList = new ArrayList();
|
||||
|
||||
GWaveLayerInfo lInfo = null;
|
||||
BufferedReader bReader = null;
|
||||
try
|
||||
{
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
String line;
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||
lInfo = new GWaveLayerInfo();
|
||||
}
|
||||
else if ((line.contains("LAYER.ACTIVATE")) || (line.contains("layer.activate"))) {
|
||||
lInfo.setActivate(line.split("\\=")[1]);
|
||||
}
|
||||
else if ((line.contains("LAYER.NAME")) || (line.contains("layer.name"))) {
|
||||
lInfo.setLayerName(line.split("\\=")[1]);
|
||||
}
|
||||
else if ((line.contains("LAYER.SOURCE")) || (line.contains("layer.source"))) {
|
||||
lInfo.setLayerSource(line.split("\\=")[1]);
|
||||
}
|
||||
else if ((line.contains("LAYER.DESC")) || (line.contains("layer.desc"))) {
|
||||
lInfo.setDesc(line.split("\\=")[1]);
|
||||
}
|
||||
else if (line.equalsIgnoreCase("[/LAYER_CONFIG]"))
|
||||
{
|
||||
if ((lInfo != null) && (lInfo.isAvailable()))
|
||||
layerInfoList.add(lInfo);
|
||||
else {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this GeoWaveLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||
}
|
||||
|
||||
lInfo = null;
|
||||
}
|
||||
}
|
||||
catch (Exception localException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] GeoWaveLayer configuration file is not valid :: " + e.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
|
||||
return layerInfoList;
|
||||
}
|
||||
|
||||
private static GeoWaveDataStore parseGWaveServerInfo(File conf)
|
||||
{
|
||||
if (!conf.exists()) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Create GeoWaveLayer Fail :: GeoWaveLayer configuration is not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isActivate = false;
|
||||
|
||||
String serverName = null;
|
||||
String serverIP = null;
|
||||
Integer serverPORT = null;
|
||||
|
||||
Integer rowCount = null;
|
||||
Integer bufferSize = null;
|
||||
|
||||
BufferedReader bReader = null;
|
||||
try
|
||||
{
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
String line;
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((line.contains("SERVER.ACTIVATE")) || (line.contains("server.activate"))) {
|
||||
isActivate = ServerUtil.getBooleanValue(line.split("\\=")[1].trim());
|
||||
}
|
||||
if ((line.contains("SERVER.NAME")) || (line.contains("server.name"))) {
|
||||
serverName = line.split("\\=")[1].trim();
|
||||
}
|
||||
else if ((line.contains("SERVER.IP")) || (line.contains("server.ip"))) {
|
||||
serverIP = line.split("\\=")[1].trim();
|
||||
}
|
||||
else if ((line.contains("SERVER.PORT")) || (line.contains("server.port"))) {
|
||||
serverPORT = Integer.valueOf(line.split("\\=")[1].trim());
|
||||
}
|
||||
else if ((line.contains("SERVER.READ.ROW")) || (line.contains("server.read.row"))) {
|
||||
rowCount = Integer.valueOf(line.split("\\=")[1].trim());
|
||||
}
|
||||
else if ((line.contains("SERVER.READ.BUFFER")) || (line.contains("server.read.buffer")))
|
||||
bufferSize = Integer.valueOf(line.split("\\=")[1].trim());
|
||||
}
|
||||
catch (Exception localException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] GeoWaveLayer configuration file is not valid :: " + e.getMessage());
|
||||
try
|
||||
{
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
bReader = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!isActivate) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: ServerActivate is FALSE");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(serverName)) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: ServerName is empty");
|
||||
return null;
|
||||
}if (dataStores.get(serverName.trim().toUpperCase()) != null) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: This ServerName is already exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(serverIP)) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: ServerIP is empty");
|
||||
return null;
|
||||
}if (serverPORT == null) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: This ServerPORT is not valid");
|
||||
return null;
|
||||
}
|
||||
|
||||
GWDriver gwDriver = null;
|
||||
try {
|
||||
gwDriver = new GWDriver(serverIP, serverPORT.intValue());
|
||||
if (gwDriver.getFeatureList().size() == 0) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: This server has zero[0] layer");
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GeoWaveDataStore(serverName, serverIP, serverPORT.intValue(), rowCount, bufferSize);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"[" + conf.getName() + "] Skip this configuration :: GeoWave Driver connection fail :: " + e);
|
||||
} finally {
|
||||
if (gwDriver != null)
|
||||
try {
|
||||
gwDriver.close();
|
||||
}
|
||||
catch (IOException localIOException4)
|
||||
{
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer()
|
||||
throws Exception
|
||||
{
|
||||
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.GEOWAVE);
|
||||
try
|
||||
{
|
||||
dirtyDataStores = dataStores;
|
||||
initLayers();
|
||||
disposeDirtyDataStores();
|
||||
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "Success to reload GeoWaveStore.");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]", "Fail to reload GeoWaveStore. Now use previous GeoWaveStore :: " + e);
|
||||
|
||||
dataStores = dirtyDataStores;
|
||||
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, true);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GeoWaveDataStore getDataStore(String storeName)
|
||||
throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(storeName))
|
||||
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||
if (dataStores.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return (GeoWaveDataStore)dataStores.get(storeName.trim().toUpperCase());
|
||||
}
|
||||
|
||||
public static synchronized void disposeDirtyDataStores()
|
||||
{
|
||||
if (dirtyDataStores == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator iter = dirtyDataStores.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
GeoWaveDataStore store = (GeoWaveDataStore)iter.next();
|
||||
store.dispose();
|
||||
|
||||
store = null;
|
||||
}
|
||||
|
||||
dirtyDataStores.clear();
|
||||
dirtyDataStores = null;
|
||||
}
|
||||
|
||||
public static synchronized void disposeDataStores()
|
||||
{
|
||||
if (dataStores.isEmpty()) return;
|
||||
|
||||
synchronized (dataStores)
|
||||
{
|
||||
for (String storeName : dataStores.keySet()) {
|
||||
GeoWaveDataStore store = (GeoWaveDataStore)dataStores.get(storeName);
|
||||
try
|
||||
{
|
||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.GEOWAVE, storeName);
|
||||
|
||||
store.dispose();
|
||||
store = null;
|
||||
|
||||
dataStores.remove(storeName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean disposeDataStore(String storeName)
|
||||
{
|
||||
if (ServerUtil.isNullString(storeName)) {
|
||||
LogMngr.getInstance().logError("[GWAVE]", "Parameter StoreName is NULL");
|
||||
return false;
|
||||
}if (dataStores.isEmpty()) {
|
||||
LogMngr.getInstance().logError("[GWAVE]", "DataStore is NULL");
|
||||
return false;
|
||||
}
|
||||
|
||||
storeName = storeName.trim().toUpperCase();
|
||||
|
||||
synchronized (dataStores)
|
||||
{
|
||||
GeoWaveDataStore store = (GeoWaveDataStore)dataStores.get(storeName);
|
||||
if (store == null) {
|
||||
LogMngr.getInstance().logError("[GWAVE]", "DataStore [" + storeName + "] is not exist");
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.GEOWAVE, storeName);
|
||||
|
||||
store.dispose();
|
||||
store = null;
|
||||
|
||||
dataStores.remove(storeName);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[GWAVE]",
|
||||
"Fail to remove layer linked this DataStore :: " + e);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,155 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.Transaction;
|
||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||
import org.geotools.data.store.ContentDataStore;
|
||||
import org.geotools.data.store.ContentEntry;
|
||||
import org.geotools.data.store.ContentFeatureCollection;
|
||||
import org.geotools.data.store.ContentFeatureSource;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.feature.NameImpl;
|
||||
import org.geotools.filter.FilterCapabilities;
|
||||
import org.opengis.feature.Feature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.Name;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.Id;
|
||||
import org.opengis.filter.identity.GmlObjectId;
|
||||
import org.opengis.filter.spatial.BBOX;
|
||||
|
||||
import com.geowave.vectordrvier.GWVectorDriver;
|
||||
|
||||
public class GeoWaveDataStore
|
||||
extends ContentDataStore {
|
||||
private final FilterCapabilities capabilities;
|
||||
private final String serverName;
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final int readRowCount;
|
||||
private final int readBufferSize;
|
||||
|
||||
public GeoWaveDataStore(String name, String ip, int port) throws Exception {
|
||||
this(name, ip, port, 1000, 10);
|
||||
}
|
||||
|
||||
public GeoWaveDataStore(String name, String ip, int port, Integer rowCount, Integer bufferSize) throws Exception {
|
||||
this.serverName = name.trim().toUpperCase();
|
||||
this.serverIP = ip.trim().toUpperCase();
|
||||
this.serverPort = port;
|
||||
if (rowCount == null) {
|
||||
rowCount = 1000;
|
||||
}
|
||||
if (bufferSize == null) {
|
||||
bufferSize = 10;
|
||||
}
|
||||
this.readRowCount = rowCount;
|
||||
this.readBufferSize = bufferSize * 1024 * 1024;
|
||||
this.capabilities = new FilterCapabilities();
|
||||
this.capabilities.addAll(FilterCapabilities.LOGICAL_OPENGIS);
|
||||
this.capabilities.addType(BBOX.class);
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
return this.serverName;
|
||||
}
|
||||
|
||||
protected List<Name> createTypeNames() throws IOException {
|
||||
ArrayList<Name> typeNames = new ArrayList<Name>();
|
||||
GWVectorDriver driver = this.getGWVDriver();
|
||||
List<String> list = driver.getFeatureList();
|
||||
for (String layerName : list) {
|
||||
typeNames.add((Name)new NameImpl(this.namespaceURI, layerName.toUpperCase()));
|
||||
}
|
||||
driver.close();
|
||||
return typeNames;
|
||||
}
|
||||
|
||||
protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException {
|
||||
SimpleFeatureType schema = entry.getState(Transaction.AUTO_COMMIT).getFeatureType();
|
||||
if (schema == null) {
|
||||
schema = new GeoWaveFeatureSource(entry).buildFeatureType();
|
||||
entry.getState(Transaction.AUTO_COMMIT).setFeatureType(schema);
|
||||
}
|
||||
return new GeoWaveFeatureSource(entry);
|
||||
}
|
||||
|
||||
public GeoWaveFeatureSource getFeatureSource(String typeName) throws IOException {
|
||||
return (GeoWaveFeatureSource)super.getFeatureSource(typeName);
|
||||
}
|
||||
|
||||
public Class<?> getMapping(String clazz) {
|
||||
if (clazz.equalsIgnoreCase("binary")) {
|
||||
return byte[].class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("byte")) {
|
||||
return Byte.TYPE;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("double")) {
|
||||
return Double.class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("float")) {
|
||||
return Float.class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("int")) {
|
||||
return Integer.class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("bigint")) {
|
||||
return Long.class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("short")) {
|
||||
return Short.class;
|
||||
}
|
||||
if (clazz.equalsIgnoreCase("string")) {
|
||||
return String.class;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GWVectorDriver getGWVDriver() {
|
||||
return new GWVectorDriver(this.serverIP, this.serverPort);
|
||||
}
|
||||
|
||||
public FilterCapabilities getFilterCapabilities() {
|
||||
return this.capabilities;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.readRowCount;
|
||||
}
|
||||
|
||||
public int getBufferSize() {
|
||||
return this.readBufferSize;
|
||||
}
|
||||
|
||||
public Object getGmlObject(GmlObjectId id, Hints hints) throws Exception {
|
||||
int i = id.getID().indexOf(46);
|
||||
if (i == -1) {
|
||||
LogMngr.getInstance().logDebug("[SHAPE]", "Unable to determine geowave type for GmlObjectId:" + id);
|
||||
return null;
|
||||
}
|
||||
String typeName = id.getID().substring(0, i);
|
||||
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||
Query query = new Query();
|
||||
query.setFilter((Filter)filter);
|
||||
query.setHints(hints);
|
||||
ContentFeatureCollection features = this.getFeatureSource(typeName).getFeatures(query);
|
||||
if (!features.isEmpty()) {
|
||||
SimpleFeatureIterator fi = features.features();
|
||||
try {
|
||||
if (fi.hasNext()) {
|
||||
Feature feature = fi.next();
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fi.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.geowave.vectordrvier.GWVectorDriver;
|
||||
import com.geowave.vectordrvier.GWVectorQuery;
|
||||
import com.geowave.vectordrvier.object.GWFeatureVectorObject;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||
import org.geotools.util.Converters;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterVisitor;
|
||||
|
||||
public class GeoWaveFeatureReader
|
||||
implements FeatureReader<SimpleFeatureType, SimpleFeature> {
|
||||
private final GWVectorDriver gwvDriver;
|
||||
private final SimpleFeatureType featureType;
|
||||
final GWVectorQuery query;
|
||||
private final int readRowCount;
|
||||
private final int readBufferSize;
|
||||
private SimpleFeatureBuilder builder;
|
||||
private ArrayList<GWFeatureVectorObject> resultList = null;
|
||||
private int featureIDX = 0;
|
||||
|
||||
public GeoWaveFeatureReader(GWVectorDriver driver, int rowCount, int bufferSize, SimpleFeatureType schema, Query q) throws IOException {
|
||||
this.gwvDriver = driver;
|
||||
this.featureType = schema;
|
||||
this.readRowCount = rowCount;
|
||||
this.readBufferSize = bufferSize;
|
||||
this.builder = new SimpleFeatureBuilder(this.featureType);
|
||||
this.gwvDriver.open_layer(this.featureType.getTypeName());
|
||||
if (q.getFilter() == null || q.getFilter() == Filter.INCLUDE) {
|
||||
this.query = null;
|
||||
this.resultList = this.gwvDriver.read_line_bulk_vector(this.readRowCount, this.readBufferSize);
|
||||
} else {
|
||||
Envelope bounds = (Envelope)q.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
this.query = new GWVectorQuery(this.gwvDriver);
|
||||
this.query.setEnvelopeFilter(bounds);
|
||||
this.resultList = this.query.getResult_vector(this.readRowCount);
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleFeatureType getFeatureType() {
|
||||
return this.featureType;
|
||||
}
|
||||
|
||||
public SimpleFeature next() throws IOException, IllegalArgumentException, NoSuchElementException {
|
||||
GWFeatureVectorObject vecObj = this.resultList.get(this.featureIDX);
|
||||
++this.featureIDX;
|
||||
String fid = String.valueOf(this.featureType.getTypeName()) + "." + SimpleFeatureBuilder.createDefaultFeatureId();
|
||||
int i = 0;
|
||||
while (i < this.featureType.getAttributeCount()) {
|
||||
Class binding;
|
||||
Object converted;
|
||||
AttributeDescriptor type = this.featureType.getDescriptor(i);
|
||||
Object value = null;
|
||||
if (type instanceof GeometryDescriptor) {
|
||||
Geometry geometry;
|
||||
GeometryDescriptor gatt = (GeometryDescriptor)type;
|
||||
value = vecObj.getGeometry();
|
||||
if (value != null && (geometry = (Geometry)value).getUserData() == null) {
|
||||
geometry.setUserData((Object)gatt.getCoordinateReferenceSystem());
|
||||
}
|
||||
} else {
|
||||
value = vecObj.getColumnObj(i);
|
||||
}
|
||||
if (value != null && (converted = Converters.convert((Object)value, (Class)(binding = type.getType().getBinding()))) != null && converted != value) {
|
||||
value = converted;
|
||||
}
|
||||
this.builder.add(value);
|
||||
++i;
|
||||
}
|
||||
try {
|
||||
return this.builder.buildFeature(fid);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNext() throws IOException {
|
||||
if (this.resultList == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.resultList.size() <= this.featureIDX) {
|
||||
this.resultList = this.query == null ? this.gwvDriver.read_line_bulk_vector(this.readRowCount, this.readBufferSize) : this.query.getResult_vector(this.readRowCount);
|
||||
this.featureIDX = 0;
|
||||
}
|
||||
return this.resultList != null;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
this.gwvDriver.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,403 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.geowave.metadata.FeatureColumnInfo;
|
||||
import com.geowave.vectordrvier.GWVectorDriver;
|
||||
import com.geowave.vectordrvier.GWVectorQuery;
|
||||
import com.geowave.vectordrvier.constant.GWVectorMetadata;
|
||||
import com.geowave.vectordrvier.object.GWFeatureVectorObject;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.geotools.data.DefaultQuery;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.FilteringFeatureReader;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.ReTypeFeatureReader;
|
||||
import org.geotools.data.store.ContentEntry;
|
||||
import org.geotools.data.store.ContentFeatureSource;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.feature.AttributeTypeBuilder;
|
||||
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||
import org.geotools.filter.FilterAttributeExtractor;
|
||||
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||
import org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterVisitor;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.crs.SingleCRS;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
public class GeoWaveFeatureSource extends ContentFeatureSource {
|
||||
private final ReferencedEnvelope EMPTY_ENVELOPE = new ReferencedEnvelope();
|
||||
|
||||
public GeoWaveFeatureSource(ContentEntry entry) {
|
||||
super(entry, Query.ALL);
|
||||
HashSet<Hints.Key> hints = new HashSet<>();
|
||||
hints.add(Hints.FEATURE_DETACHED);
|
||||
hints.add(Hints.JTS_GEOMETRY_FACTORY);
|
||||
hints.add(Hints.JTS_COORDINATE_SEQUENCE_FACTORY);
|
||||
hints.add(Hints.GEOMETRY_DISTANCE);
|
||||
hints.add(Hints.SCREENMAP);
|
||||
this.hints = Collections.unmodifiableSet(hints);
|
||||
}
|
||||
|
||||
protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException {
|
||||
Filter[] split = this.splitFilter(query.getFilter());
|
||||
Filter preFilter = split[0];
|
||||
Filter postFilter = split[1];
|
||||
try {
|
||||
if (postFilter != null && postFilter != Filter.INCLUDE || query.getMaxFeatures() < Integer.MAX_VALUE && !this.canLimit() || query.getStartIndex() != null && query.getStartIndex() > 0 && !this.canOffset()) {
|
||||
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||
ReferencedEnvelope bounds = new ReferencedEnvelope((CoordinateReferenceSystem)flatCRS);
|
||||
FeatureReader i = this.getReader(query);
|
||||
try {
|
||||
if (i.hasNext()) {
|
||||
SimpleFeature f = (SimpleFeature)i.next();
|
||||
bounds.init(f.getBounds());
|
||||
while (i.hasNext()) {
|
||||
f = (SimpleFeature)i.next();
|
||||
bounds.include(f.getBounds());
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
i.close();
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
DefaultQuery q = new DefaultQuery(query);
|
||||
q.setFilter(preFilter);
|
||||
return this.getBoundsOptimal((Query)q);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected ReferencedEnvelope getBoundsOptimal(Query query) throws IOException {
|
||||
if (this.getSchema().getGeometryDescriptor() == null) {
|
||||
return this.EMPTY_ENVELOPE;
|
||||
}
|
||||
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||
try {
|
||||
ArrayList<GWFeatureVectorObject> result;
|
||||
driver.open_layer(this.getSchema().getTypeName());
|
||||
if (this.isFullBoundsQuery(query)) {
|
||||
GWVectorMetadata meta = driver.getVectorMeta(this.getSchema().getTypeName());
|
||||
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(meta.getFull_envelope(), meta.getCRS());
|
||||
return referencedEnvelope;
|
||||
}
|
||||
Envelope envelop = (Envelope)query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
GWVectorQuery driverQuery = new GWVectorQuery(driver);
|
||||
driverQuery.setEnvelopeFilter(envelop);
|
||||
ReferencedEnvelope bounds = ReferencedEnvelope.create((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||
while ((result = driverQuery.getResult_vector(this.getDataStore().getRowCount())) != null) {
|
||||
for (GWFeatureVectorObject obj : result) {
|
||||
Envelope env = obj.getEnvelope();
|
||||
bounds = this.mergeEnvelope(bounds, new ReferencedEnvelope(env, (CoordinateReferenceSystem)flatCRS));
|
||||
}
|
||||
}
|
||||
ReferencedEnvelope referencedEnvelope = bounds;
|
||||
return referencedEnvelope;
|
||||
}
|
||||
catch (Exception e) {
|
||||
String msg = "Error occured calculating bounds for " + this.getSchema().getTypeName();
|
||||
throw (IOException)new IOException(msg).initCause(e);
|
||||
}
|
||||
finally {
|
||||
driver.close();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFullBoundsQuery(Query query) {
|
||||
if (query == null) {
|
||||
return true;
|
||||
}
|
||||
if (!Filter.INCLUDE.equals(query.getFilter())) {
|
||||
return false;
|
||||
}
|
||||
if (query.getProperties() == Query.ALL_PROPERTIES) {
|
||||
return true;
|
||||
}
|
||||
List<String> names = Arrays.asList(query.getPropertyNames());
|
||||
for (AttributeDescriptor ad : this.getSchema().getAttributeDescriptors()) {
|
||||
if (!(ad instanceof GeometryDescriptor) || names.contains(ad.getLocalName())) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ReferencedEnvelope mergeEnvelope(ReferencedEnvelope base, ReferencedEnvelope merge) throws TransformException, FactoryException {
|
||||
if (base == null || base.isNull()) {
|
||||
return merge;
|
||||
}
|
||||
if (merge == null || merge.isNull()) {
|
||||
return base;
|
||||
}
|
||||
CoordinateReferenceSystem crsBase = base.getCoordinateReferenceSystem();
|
||||
CoordinateReferenceSystem crsMerge = merge.getCoordinateReferenceSystem();
|
||||
if (crsBase == null) {
|
||||
merge.expandToInclude((Envelope)base);
|
||||
return merge;
|
||||
}
|
||||
if (crsMerge == null) {
|
||||
base.expandToInclude((Envelope)base);
|
||||
return base;
|
||||
}
|
||||
if (!CRS.equalsIgnoreMetadata((Object)crsBase, (Object)crsMerge)) {
|
||||
merge = merge.transform(crsBase, true);
|
||||
}
|
||||
base.expandToInclude((Envelope)merge);
|
||||
return base;
|
||||
}
|
||||
|
||||
protected int getCountInternal(Query query) throws IOException {
|
||||
Filter[] split = this.splitFilter(query.getFilter());
|
||||
Filter preFilter = split[0];
|
||||
Filter postFilter = split[1];
|
||||
try {
|
||||
boolean manual;
|
||||
boolean bl = manual = postFilter != null && postFilter != Filter.INCLUDE;
|
||||
if (manual) {
|
||||
int count = 0;
|
||||
FeatureReader reader = this.getReader(query);
|
||||
try {
|
||||
while (reader.hasNext()) {
|
||||
reader.next();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
DefaultQuery q = new DefaultQuery(query);
|
||||
q.setFilter(preFilter);
|
||||
int count = this.getCountOptimal((Query)q);
|
||||
if (query.getStartIndex() != null && query.getStartIndex() > 0) {
|
||||
count = query.getStartIndex() > count ? 0 : (count -= query.getStartIndex().intValue());
|
||||
}
|
||||
if (query.getMaxFeatures() > 0 && count > query.getMaxFeatures()) {
|
||||
count = query.getMaxFeatures();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getCountOptimal(Query query) throws IOException {
|
||||
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||
try {
|
||||
ArrayList result;
|
||||
driver.open_layer(this.getSchema().getTypeName());
|
||||
if (this.isFullBoundsQuery(query)) {
|
||||
GWVectorMetadata meta = driver.getVectorMeta(this.getSchema().getTypeName());
|
||||
int n = meta.getTotal_row_count();
|
||||
return n;
|
||||
}
|
||||
int count = 0;
|
||||
Envelope envelop = (Envelope)query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
GWVectorQuery driverQuery = new GWVectorQuery(driver);
|
||||
driverQuery.setEnvelopeFilter(envelop);
|
||||
ReferencedEnvelope bounds = ReferencedEnvelope.create((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||
while ((result = driverQuery.getResult_vector(this.getDataStore().getRowCount())) != null) {
|
||||
count += result.size();
|
||||
}
|
||||
int n = count;
|
||||
return n;
|
||||
}
|
||||
catch (Exception e) {
|
||||
String msg = "Error occured calculating bounds for " + this.getSchema().getTypeName();
|
||||
throw (IOException)new IOException(msg).initCause(e);
|
||||
}
|
||||
finally {
|
||||
driver.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException {
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> reader;
|
||||
Filter[] split = this.splitFilter(query.getFilter());
|
||||
Filter preFilter = split[0];
|
||||
Filter postFilter = split[1];
|
||||
DefaultQuery preQuery = new DefaultQuery(query);
|
||||
preQuery.setFilter(preFilter);
|
||||
SimpleFeatureType[] types = this.buildQueryAndReturnFeatureTypes(query.getPropertyNames(), postFilter);
|
||||
SimpleFeatureType querySchema = types[0];
|
||||
SimpleFeatureType returnedSchema = types[1];
|
||||
try {
|
||||
reader = new GeoWaveFeatureReader(this.getDataStore().getGWVDriver(), this.getDataStore().getRowCount(), this.getDataStore().getBufferSize(), querySchema, (Query)preQuery);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (e instanceof Error) {
|
||||
throw (Error)e;
|
||||
}
|
||||
throw (IOException)new IOException().initCause(e);
|
||||
}
|
||||
if (postFilter != null && postFilter != Filter.INCLUDE) {
|
||||
reader = new FilteringFeatureReader((FeatureReader)reader, postFilter);
|
||||
if (!returnedSchema.equals((Object)querySchema)) {
|
||||
reader = new ReTypeFeatureReader((FeatureReader)reader, returnedSchema);
|
||||
}
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
private SimpleFeatureType[] buildQueryAndReturnFeatureTypes(String[] propertyNames, Filter filter) {
|
||||
SimpleFeatureType returnedSchema;
|
||||
SimpleFeatureType[] types = null;
|
||||
if (propertyNames == Query.ALL_NAMES) {
|
||||
return new SimpleFeatureType[]{this.getSchema(), this.getSchema()};
|
||||
}
|
||||
SimpleFeatureType querySchema = returnedSchema = SimpleFeatureTypeBuilder.retype((SimpleFeatureType)this.getSchema(), (String[])propertyNames);
|
||||
if (filter != null && !filter.equals(Filter.INCLUDE)) {
|
||||
FilterAttributeExtractor extractor = new FilterAttributeExtractor(this.getSchema());
|
||||
filter.accept((FilterVisitor)extractor, null);
|
||||
String[] extraAttributes = extractor.getAttributeNames();
|
||||
if (extraAttributes != null && extraAttributes.length > 0) {
|
||||
ArrayList<String> allAttributes = new ArrayList<String>(Arrays.asList(propertyNames));
|
||||
String[] stringArray = extraAttributes;
|
||||
int n = extraAttributes.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
String extraAttribute = stringArray[n2];
|
||||
if (!allAttributes.contains(extraAttribute)) {
|
||||
allAttributes.add(extraAttribute);
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
String[] allAttributeArray = allAttributes.toArray(new String[allAttributes.size()]);
|
||||
querySchema = SimpleFeatureTypeBuilder.retype((SimpleFeatureType)this.getSchema(), (String[])allAttributeArray);
|
||||
}
|
||||
}
|
||||
types = new SimpleFeatureType[]{querySchema, returnedSchema};
|
||||
return types;
|
||||
}
|
||||
|
||||
protected SimpleFeatureType buildFeatureType() throws IOException {
|
||||
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
|
||||
AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
|
||||
String layerName = this.entry.getName().getLocalPart();
|
||||
typeBuilder.setName(layerName);
|
||||
if (this.entry.getName().getNamespaceURI() != null) {
|
||||
typeBuilder.setNamespaceURI(this.entry.getName().getNamespaceURI());
|
||||
} else {
|
||||
typeBuilder.setNamespaceURI(this.getDataStore().getNamespaceURI());
|
||||
}
|
||||
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||
try {
|
||||
driver.open_layer(layerName);
|
||||
GWVectorMetadata meta = driver.getVectorMeta(layerName);
|
||||
FeatureColumnInfo cInfo = meta.getColumn_info();
|
||||
int idx = 0;
|
||||
while (idx < cInfo.getColumnSize()) {
|
||||
String columnName = cInfo.getColumnName(idx).toUpperCase();
|
||||
String columnType = cInfo.getColumnType(idx);
|
||||
Class<?> binding = this.getDataStore().getMapping(columnType);
|
||||
if (columnName != null && binding != null) {
|
||||
attrBuilder.addUserData((Object)"org.geotools.jdbc.nativeTypeName", (Object)columnType);
|
||||
AttributeDescriptor attrDesc = null;
|
||||
if (idx == meta.getSpatial_column_idx()) {
|
||||
Integer srid = null;
|
||||
CoordinateReferenceSystem crs = meta.getCRS();
|
||||
try {
|
||||
srid = Integer.valueOf(CRS.toSRS((CoordinateReferenceSystem)crs, (boolean)true));
|
||||
}
|
||||
catch (Exception e) {
|
||||
srid = null;
|
||||
}
|
||||
int dimension = 2;
|
||||
switch (meta.getSpatial_type()) {
|
||||
case 1: {
|
||||
attrBuilder.setBinding(Point.class);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
attrBuilder.setBinding(LineString.class);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
attrBuilder.setBinding(Polygon.class);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
attrBuilder.setBinding(binding);
|
||||
}
|
||||
}
|
||||
attrBuilder.setName(columnName);
|
||||
attrBuilder.setCRS(crs);
|
||||
if (srid != null) {
|
||||
attrBuilder.addUserData((Object)"nativeSRID", (Object)srid);
|
||||
}
|
||||
attrBuilder.addUserData((Object)Hints.COORDINATE_DIMENSION, (Object)dimension);
|
||||
attrDesc = attrBuilder.buildDescriptor(columnName, attrBuilder.buildGeometryType());
|
||||
} else {
|
||||
attrBuilder.setBinding(binding);
|
||||
attrBuilder.setName(columnName);
|
||||
attrDesc = attrBuilder.buildDescriptor(columnName, attrBuilder.buildType());
|
||||
}
|
||||
typeBuilder.add(attrDesc);
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
SimpleFeatureType ft = typeBuilder.buildFeatureType();
|
||||
ft.getUserData().put("org.geotools.jdbc.readOnly", Boolean.TRUE);
|
||||
SimpleFeatureType simpleFeatureType = ft;
|
||||
return simpleFeatureType;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
finally {
|
||||
if (driver != null) {
|
||||
driver.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GeoWaveDataStore getDataStore() {
|
||||
return (GeoWaveDataStore)super.getDataStore();
|
||||
}
|
||||
|
||||
private Filter[] splitFilter(Filter original) {
|
||||
Filter[] split = new Filter[2];
|
||||
if (original != null) {
|
||||
PostPreProcessFilterSplittingVisitor splitter = new PostPreProcessFilterSplittingVisitor(this.getDataStore().getFilterCapabilities(), this.getSchema(), null);
|
||||
original.accept((FilterVisitor)splitter, null);
|
||||
split[0] = splitter.getFilterPre();
|
||||
split[1] = splitter.getFilterPost();
|
||||
}
|
||||
return split;
|
||||
}
|
||||
|
||||
protected boolean canFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean canTransact() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean canRetype() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,335 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.CoordinateList;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryCollection;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.MultiLineString;
|
||||
import com.vividsolutions.jts.geom.MultiPoint;
|
||||
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import oracle.jdbc.OracleConnection;
|
||||
import oracle.sql.ARRAY;
|
||||
import oracle.sql.ArrayDescriptor;
|
||||
import oracle.sql.CHAR;
|
||||
import oracle.sql.CharacterSet;
|
||||
import oracle.sql.Datum;
|
||||
import oracle.sql.NUMBER;
|
||||
import oracle.sql.STRUCT;
|
||||
import oracle.sql.StructDescriptor;
|
||||
|
||||
public class GeometryConverter
|
||||
{
|
||||
protected OracleConnection connection;
|
||||
GeometryFactory geometryFactory;
|
||||
public static final String DATATYPE = "MDSYS.SDO_GEOMETRY";
|
||||
|
||||
public GeometryConverter(OracleConnection connection)
|
||||
{
|
||||
this(connection, new GeometryFactory());
|
||||
}
|
||||
public GeometryConverter(OracleConnection connection, GeometryFactory geometryFactory) {
|
||||
this.geometryFactory = geometryFactory;
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public String getDataTypeName()
|
||||
{
|
||||
return "MDSYS.SDO_GEOMETRY";
|
||||
}
|
||||
|
||||
public boolean isCapable(Geometry geom)
|
||||
{
|
||||
if (geom == null) return true;
|
||||
if (((geom instanceof Point)) || ((geom instanceof MultiPoint)) ||
|
||||
((geom instanceof LineString)) || ((geom instanceof MultiLineString)) ||
|
||||
((geom instanceof Polygon)) || ((geom instanceof MultiPolygon)) ||
|
||||
((geom instanceof GeometryCollection)))
|
||||
{
|
||||
int d = SDO.D(geom);
|
||||
int l = SDO.L(geom);
|
||||
return (l == 0) && ((d == 2) || (d == 3));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Geometry asGeometry(STRUCT sdoGeometry)
|
||||
throws SQLException
|
||||
{
|
||||
if (sdoGeometry == null) return null;
|
||||
|
||||
Datum[] data = sdoGeometry.getOracleAttributes();
|
||||
int GTYPE = asInteger(data[0], 0);
|
||||
int SRID = asInteger(data[1], -1);
|
||||
double[] POINT = asDoubleArray((STRUCT)data[2], (0.0D / 0.0D));
|
||||
int[] ELEMINFO = asIntArray((ARRAY)data[3], 0);
|
||||
double[] ORDINATES = asDoubleArray((ARRAY)data[4], (0.0D / 0.0D));
|
||||
|
||||
return SDO.create(this.geometryFactory,
|
||||
GTYPE,
|
||||
SRID,
|
||||
POINT,
|
||||
ELEMINFO,
|
||||
ORDINATES);
|
||||
}
|
||||
|
||||
public STRUCT toSDO(Geometry geom)
|
||||
throws SQLException
|
||||
{
|
||||
return toSDO(geom, geom.getSRID());
|
||||
}
|
||||
|
||||
public STRUCT toSDO(Geometry geom, int srid)
|
||||
throws SQLException
|
||||
{
|
||||
if (geom == null) return asEmptyDataType();
|
||||
|
||||
int gtype = SDO.gType(geom);
|
||||
NUMBER SDO_GTYPE = new NUMBER(gtype);
|
||||
|
||||
NUMBER SDO_SRID = (srid == -1) || (srid == 0) ? null :
|
||||
new NUMBER(srid);
|
||||
|
||||
double[] point = SDO.point(geom);
|
||||
ARRAY SDO_ORDINATES;
|
||||
STRUCT SDO_POINT;
|
||||
ARRAY SDO_ELEM_INFO;
|
||||
if (point == null) {
|
||||
Envelope env = geom.getEnvelopeInternal();
|
||||
if ((env.getWidth() > 0.0D) && (env.getHeight() > 0.0D) && (!(geom instanceof GeometryCollection)) && (geom.isRectangle()))
|
||||
{
|
||||
SDO_POINT = null;
|
||||
int[] elemInfo = { 1, 1003, 3 };
|
||||
double[] ordinates;
|
||||
if (SDO.D(geom) == 2)
|
||||
ordinates = new double[] { env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY() };
|
||||
else {
|
||||
ordinates = new double[] { env.getMinX(), env.getMinY(), 0.0D, env.getMaxX(), env.getMaxY(), 0.0D };
|
||||
}
|
||||
SDO_POINT = null;
|
||||
SDO_ELEM_INFO = toARRAY(elemInfo, "MDSYS.SDO_ELEM_INFO_ARRAY");
|
||||
SDO_ORDINATES = toARRAY(ordinates, "MDSYS.SDO_ORDINATE_ARRAY");
|
||||
} else {
|
||||
int[] elemInfo = SDO.elemInfo(geom);
|
||||
double[] ordinates = SDO.ordinates(geom);
|
||||
|
||||
SDO_POINT = null;
|
||||
SDO_ELEM_INFO = toARRAY(elemInfo, "MDSYS.SDO_ELEM_INFO_ARRAY");
|
||||
SDO_ORDINATES = toARRAY(ordinates, "MDSYS.SDO_ORDINATE_ARRAY");
|
||||
}
|
||||
} else {
|
||||
Datum[] data = {
|
||||
toNUMBER(point[0]),
|
||||
toNUMBER(point[1]),
|
||||
toNUMBER(point[2]) };
|
||||
|
||||
SDO_POINT = toSTRUCT(data, "MDSYS.SDO_POINT_TYPE");
|
||||
SDO_ELEM_INFO = null;
|
||||
SDO_ORDINATES = null;
|
||||
}
|
||||
Datum[] attributes = {
|
||||
SDO_GTYPE,
|
||||
SDO_SRID,
|
||||
SDO_POINT,
|
||||
SDO_ELEM_INFO,
|
||||
SDO_ORDINATES };
|
||||
|
||||
return toSTRUCT(attributes, "MDSYS.SDO_GEOMETRY");
|
||||
}
|
||||
|
||||
protected STRUCT asEmptyDataType()
|
||||
throws SQLException
|
||||
{
|
||||
return toSTRUCT(null, "MDSYS.SDO_GEOMETRY");
|
||||
}
|
||||
|
||||
protected final STRUCT toSTRUCT(Datum[] attributes, String dataType)
|
||||
throws SQLException
|
||||
{
|
||||
if (dataType.startsWith("*.")) {
|
||||
dataType = "DRA." + dataType.substring(2);
|
||||
}
|
||||
StructDescriptor descriptor =
|
||||
StructDescriptor.createDescriptor(dataType, this.connection);
|
||||
|
||||
return new STRUCT(descriptor, this.connection, attributes);
|
||||
}
|
||||
|
||||
protected final ARRAY toARRAY(double[] doubles, String dataType)
|
||||
throws SQLException
|
||||
{
|
||||
ArrayDescriptor descriptor =
|
||||
ArrayDescriptor.createDescriptor(dataType, this.connection);
|
||||
|
||||
return new ARRAY(descriptor, this.connection, doubles);
|
||||
}
|
||||
|
||||
protected final ARRAY toORDINATE(CoordinateList list, double[][] measures, int D)
|
||||
throws SQLException
|
||||
{
|
||||
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
|
||||
"MDSYS.SDO_ORDINATE_ARRAY",
|
||||
this.connection);
|
||||
|
||||
int LENGTH = measures != null ? measures.length : 0;
|
||||
int LEN = D + LENGTH;
|
||||
Datum[] data = new Datum[list.size() * LEN];
|
||||
int offset = 0;
|
||||
int index = 0;
|
||||
|
||||
for (Iterator i = list.iterator(); i.hasNext(); index++)
|
||||
{
|
||||
Coordinate coord = (Coordinate)i.next();
|
||||
|
||||
data[(offset++)] = toNUMBER(coord.x);
|
||||
data[(offset++)] = toNUMBER(coord.y);
|
||||
if (D == 3)
|
||||
{
|
||||
data[(offset++)] = toNUMBER(coord.x);
|
||||
}
|
||||
for (int j = 0; j < LENGTH; j++)
|
||||
{
|
||||
data[(offset++)] = toNUMBER(measures[j][index]);
|
||||
}
|
||||
}
|
||||
return new ARRAY(descriptor, this.connection, data);
|
||||
}
|
||||
|
||||
protected final ARRAY toORDINATE(double[] ords) throws SQLException
|
||||
{
|
||||
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
|
||||
"MDSYS.SDO_ORDINATE_ARRAY",
|
||||
this.connection);
|
||||
|
||||
int LENGTH = ords.length;
|
||||
|
||||
Datum[] data = new Datum[LENGTH];
|
||||
|
||||
for (int i = 0; i < LENGTH; i++)
|
||||
{
|
||||
data[i] = toNUMBER(ords[i]);
|
||||
}
|
||||
return new ARRAY(descriptor, this.connection, data);
|
||||
}
|
||||
|
||||
protected final ARRAY toATTRIBUTE(double[] ords, String desc) throws SQLException
|
||||
{
|
||||
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
|
||||
desc,
|
||||
this.connection);
|
||||
|
||||
int LENGTH = ords.length;
|
||||
|
||||
Datum[] data = new Datum[LENGTH];
|
||||
|
||||
for (int i = 0; i < LENGTH; i++)
|
||||
{
|
||||
data[i] = toNUMBER(ords[i]);
|
||||
}
|
||||
return new ARRAY(descriptor, this.connection, data);
|
||||
}
|
||||
|
||||
protected final NUMBER toNUMBER(double number)
|
||||
throws SQLException
|
||||
{
|
||||
if (Double.isNaN(number)) {
|
||||
return null;
|
||||
}
|
||||
return new NUMBER(number);
|
||||
}
|
||||
|
||||
protected final ARRAY toARRAY(int[] ints, String dataType)
|
||||
throws SQLException
|
||||
{
|
||||
ArrayDescriptor descriptor =
|
||||
ArrayDescriptor.createDescriptor(dataType, this.connection);
|
||||
|
||||
return new ARRAY(descriptor, this.connection, ints);
|
||||
}
|
||||
|
||||
protected final NUMBER toNUMBER(int number)
|
||||
{
|
||||
return new NUMBER(number);
|
||||
}
|
||||
|
||||
protected final CHAR toCHAR(String s)
|
||||
{
|
||||
if (s.length() > 1)
|
||||
s = new String(new Character(s.charAt(0)).toString());
|
||||
try
|
||||
{
|
||||
return new CHAR(s, CharacterSet.make(31));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int asInteger(Datum datum, int DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (datum == null) return DEFAULT;
|
||||
return ((NUMBER)datum).intValue();
|
||||
}
|
||||
|
||||
protected double asDouble(Datum datum, double DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (datum == null) return DEFAULT;
|
||||
return ((NUMBER)datum).doubleValue();
|
||||
}
|
||||
|
||||
protected double[] asDoubleArray(STRUCT struct, double DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (struct == null) return null;
|
||||
return asDoubleArray(struct.getOracleAttributes(), DEFAULT);
|
||||
}
|
||||
|
||||
protected double[] asDoubleArray(ARRAY array, double DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (array == null) return null;
|
||||
if (DEFAULT == 0.0D) return array.getDoubleArray();
|
||||
|
||||
return asDoubleArray(array.getOracleArray(), DEFAULT);
|
||||
}
|
||||
|
||||
protected double[] asDoubleArray(Datum[] data, double DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (data == null) return null;
|
||||
double[] array = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
{
|
||||
array[i] = asDouble(data[i], DEFAULT);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
protected int[] asIntArray(ARRAY array, int DEFAULT) throws SQLException
|
||||
{
|
||||
if (array == null) return null;
|
||||
if (DEFAULT == 0) return array.getIntArray();
|
||||
|
||||
return asIntArray(array.getOracleArray(), DEFAULT);
|
||||
}
|
||||
|
||||
protected int[] asIntArray(Datum[] data, int DEFAULT)
|
||||
throws SQLException
|
||||
{
|
||||
if (data == null) return null;
|
||||
int[] array = new int[data.length];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
{
|
||||
array[i] = asInteger(data[i], DEFAULT);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.MultiLineString;
|
||||
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.feature.type.GeometryType;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
public class GeometryMngr
|
||||
{
|
||||
public static GeomType getGeometryTypeByLayer(Layer layer)
|
||||
throws Exception
|
||||
{
|
||||
if ((layer instanceof FeatureLayer)) {
|
||||
FeatureLayer fLayer = (FeatureLayer)layer;
|
||||
return getGeometryType(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GeomType getGeometryType(LayerFactory.LayerType layerType, String serverName, String tableName)
|
||||
throws Exception
|
||||
{
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(layerType, serverName, tableName);
|
||||
|
||||
GeometryDescriptor geomDesc = ((SimpleFeatureType)featureSource.getSchema()).getGeometryDescriptor();
|
||||
|
||||
Class clazz = geomDesc.getType().getBinding();
|
||||
|
||||
if ((Polygon.class.isAssignableFrom(clazz)) ||
|
||||
(MultiPolygon.class.isAssignableFrom(clazz)))
|
||||
{
|
||||
return GeomType.POLYGON;
|
||||
}
|
||||
if ((LineString.class.isAssignableFrom(clazz)) ||
|
||||
(MultiLineString.class.isAssignableFrom(clazz)))
|
||||
{
|
||||
return GeomType.LINE;
|
||||
}
|
||||
|
||||
return GeomType.POINT;
|
||||
}
|
||||
|
||||
public static String getGeometryColumnByLayer(Layer layer)
|
||||
throws Exception
|
||||
{
|
||||
if ((layer instanceof FeatureLayer)) {
|
||||
FeatureLayer fLayer = (FeatureLayer)layer;
|
||||
return getGeometryColumn(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getGeometryColumn(LayerFactory.LayerType layerType, String serverName, String tableName)
|
||||
throws Exception
|
||||
{
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(layerType, serverName, tableName);
|
||||
|
||||
GeometryDescriptor geomDesc = ((SimpleFeatureType)featureSource.getSchema()).getGeometryDescriptor();
|
||||
|
||||
return geomDesc.getLocalName();
|
||||
}
|
||||
|
||||
public static ReferencedEnvelope mergeEnvelope(ReferencedEnvelope base, ReferencedEnvelope merge)
|
||||
throws TransformException, FactoryException
|
||||
{
|
||||
if ((base == null) || (base.isNull()))
|
||||
return merge;
|
||||
if ((merge == null) || (merge.isNull())) {
|
||||
return base;
|
||||
}
|
||||
|
||||
CoordinateReferenceSystem crsBase = base.getCoordinateReferenceSystem();
|
||||
CoordinateReferenceSystem crsMerge = merge.getCoordinateReferenceSystem();
|
||||
if (crsBase == null) {
|
||||
merge.expandToInclude(base);
|
||||
return merge;
|
||||
}if (crsMerge == null) {
|
||||
base.expandToInclude(merge);
|
||||
return base;
|
||||
}
|
||||
|
||||
if (!CRS.equalsIgnoreMetadata(crsBase, crsMerge)) {
|
||||
merge = merge.transform(crsBase, true);
|
||||
}
|
||||
base.expandToInclude(merge);
|
||||
return base;
|
||||
}
|
||||
|
||||
public static enum GeomType
|
||||
{
|
||||
POINT, LINE, POLYGON;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
public class GetCapabilitiesRequest extends Request
|
||||
{
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class GetFeatureInfoRequest extends Request
|
||||
{
|
||||
private String[] layers = null;
|
||||
private String[] styles = null;
|
||||
private CoordinateReferenceSystem crs = null;
|
||||
private ReferencedEnvelope bbox = null;
|
||||
private int width;
|
||||
private int height;
|
||||
private String[] queryLayer;
|
||||
private String infoFormat;
|
||||
private int i;
|
||||
private int j;
|
||||
private int featureCount = 1;
|
||||
|
||||
private StyledLayerDescriptor sld = null;
|
||||
|
||||
public StyledLayerDescriptor getSld() {
|
||||
return this.sld;
|
||||
}
|
||||
public void setSld(StyledLayerDescriptor sld) {
|
||||
this.sld = sld;
|
||||
}
|
||||
public String[] getLayers() {
|
||||
return this.layers;
|
||||
}
|
||||
public void setLayers(String[] layers) {
|
||||
this.layers = layers;
|
||||
}
|
||||
public String[] getStyles() {
|
||||
return this.styles;
|
||||
}
|
||||
public void setStyles(String[] styles) {
|
||||
this.styles = styles;
|
||||
}
|
||||
public ReferencedEnvelope getBbox() {
|
||||
return this.bbox;
|
||||
}
|
||||
public void setBbox(ReferencedEnvelope bbox) {
|
||||
this.bbox = bbox;
|
||||
}
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
public String[] getQueryLayer() {
|
||||
return this.queryLayer;
|
||||
}
|
||||
public void setQueryLayer(String[] queryLayer) {
|
||||
this.queryLayer = queryLayer;
|
||||
}
|
||||
public String getInfoFormat() {
|
||||
return this.infoFormat;
|
||||
}
|
||||
public void setInfoFormat(String infoFormat) {
|
||||
this.infoFormat = infoFormat;
|
||||
}
|
||||
public int getI() {
|
||||
return this.i;
|
||||
}
|
||||
public void setI(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
public int getJ() {
|
||||
return this.j;
|
||||
}
|
||||
public void setJ(int j) {
|
||||
this.j = j;
|
||||
}
|
||||
public void setCRS(CoordinateReferenceSystem crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
return this.crs;
|
||||
}
|
||||
public int getFeatureCount() {
|
||||
return this.featureCount;
|
||||
}
|
||||
public void setFeatureCount(int featureCount) {
|
||||
this.featureCount = featureCount;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
|
||||
public class GetLegendGraphicRequest extends Request
|
||||
{
|
||||
private String layer;
|
||||
private String style;
|
||||
private String rule;
|
||||
private StyledLayerDescriptor sld;
|
||||
private String width;
|
||||
private String height;
|
||||
private String scale;
|
||||
private String option;
|
||||
|
||||
public String getLayer()
|
||||
{
|
||||
return this.layer;
|
||||
}
|
||||
public void setLayer(String layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
public String getStyle() {
|
||||
return this.style;
|
||||
}
|
||||
public void setStyle(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
public void setRule(String rule) {
|
||||
this.rule = rule;
|
||||
}
|
||||
public StyledLayerDescriptor getSld() {
|
||||
return this.sld;
|
||||
}
|
||||
public void setSld(StyledLayerDescriptor sld) {
|
||||
this.sld = sld;
|
||||
}
|
||||
public String getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
public void setWidth(String width) {
|
||||
this.width = width;
|
||||
}
|
||||
public String getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
public void setHeight(String height) {
|
||||
this.height = height;
|
||||
}
|
||||
public String getRule() {
|
||||
return this.rule;
|
||||
}
|
||||
public String getScale() {
|
||||
return this.scale;
|
||||
}
|
||||
public void setScale(String scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
public String getOption() {
|
||||
return this.option;
|
||||
}
|
||||
public void setOption(String option) {
|
||||
this.option = option;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
|
||||
public class GetMapRequest extends Request {
|
||||
private String[] layers = null;
|
||||
private String[] styles = null;
|
||||
private ReferencedEnvelope bbox = null;
|
||||
private int width;
|
||||
private int height;
|
||||
private boolean transparent = false;
|
||||
private Color bgcolor = Color.white;
|
||||
private StyledLayerDescriptor sld = null;
|
||||
|
||||
public String[] getLayers() {
|
||||
return this.layers;
|
||||
}
|
||||
|
||||
public void setLayers(String[] layers) {
|
||||
this.layers = layers;
|
||||
}
|
||||
|
||||
public String[] getStyles() {
|
||||
return this.styles;
|
||||
}
|
||||
|
||||
public void setStyles(String[] styles) {
|
||||
this.styles = styles;
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBbox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public void setBbox(ReferencedEnvelope bbox) {
|
||||
this.bbox = bbox;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this.transparent;
|
||||
}
|
||||
|
||||
public void setTransparent(boolean transparent) {
|
||||
this.transparent = transparent;
|
||||
}
|
||||
|
||||
public Color getBgcolor() {
|
||||
return this.bgcolor;
|
||||
}
|
||||
|
||||
public void setBgcolor(Color bgcolor) {
|
||||
this.bgcolor = bgcolor;
|
||||
}
|
||||
|
||||
public StyledLayerDescriptor getSld() {
|
||||
return this.sld;
|
||||
}
|
||||
|
||||
public void setSld(StyledLayerDescriptor sld) {
|
||||
this.sld = sld;
|
||||
}
|
||||
|
||||
public GetMapRequest clone() {
|
||||
GetMapRequest newRequest = new GetMapRequest();
|
||||
newRequest.layers = (String[])this.layers.clone();
|
||||
newRequest.bbox = ReferencedEnvelope.reference((ReferencedEnvelope)this.bbox);
|
||||
newRequest.bgcolor = new Color(this.bgcolor.getRed(), this.bgcolor.getGreen(), this.bgcolor.getBlue(), this.bgcolor.getTransparency());
|
||||
newRequest.transparent = this.transparent;
|
||||
newRequest.height = this.height;
|
||||
newRequest.width = this.width;
|
||||
if (this.styles != null) {
|
||||
newRequest.styles = (String[])this.styles.clone();
|
||||
}
|
||||
if (this.sld != null) {
|
||||
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||
visitor.visit(this.sld);
|
||||
newRequest.sld = (StyledLayerDescriptor)visitor.getCopy();
|
||||
}
|
||||
return newRequest;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class GroupLayer extends Layer
|
||||
{
|
||||
private ReferencedEnvelope bbox;
|
||||
private String sourceName;
|
||||
private ArrayList<FeatureLayer> layerList = new ArrayList();
|
||||
|
||||
public GroupLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try
|
||||
{
|
||||
this.sourceName = params.getStringValue("conf.service.ref.source");
|
||||
String[] layers = this.sourceName.split(",");
|
||||
|
||||
ReferencedEnvelope layerBBox = null;
|
||||
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
try
|
||||
{
|
||||
FeatureLayer layer = (FeatureLayer)ServerContext.getMap().getLayer(layers[i]);
|
||||
|
||||
if (layerBBox == null)
|
||||
layerBBox = layer.getBBox();
|
||||
else {
|
||||
layerBBox.expandToInclude(layer.getBBox());
|
||||
}
|
||||
|
||||
this.layerList.add(i, layer);
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException("Layer [" + layers[i].trim() + "] is not exits.");
|
||||
}
|
||||
}
|
||||
|
||||
this.bbox = layerBBox;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox()
|
||||
{
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public String getServerName()
|
||||
{
|
||||
return super.getServerName().toUpperCase();
|
||||
}
|
||||
|
||||
public String getSourceName()
|
||||
{
|
||||
return this.sourceName;
|
||||
}
|
||||
|
||||
public ArrayList<FeatureLayer> getLayerList() {
|
||||
return this.layerList;
|
||||
}
|
||||
|
||||
public void updateCRS()
|
||||
{
|
||||
super.updateCRS();
|
||||
updateBBox();
|
||||
}
|
||||
|
||||
public void updateBBox()
|
||||
{
|
||||
try {
|
||||
ReferencedEnvelope layerBBox = null;
|
||||
|
||||
for (int i = 0; i < this.layerList.size(); i++)
|
||||
{
|
||||
FeatureLayer layer = (FeatureLayer)this.layerList.get(i);
|
||||
|
||||
if (layerBBox == null)
|
||||
layerBBox = layer.getBBox();
|
||||
else {
|
||||
layerBBox.expandToInclude(layer.getBBox());
|
||||
}
|
||||
}
|
||||
|
||||
this.bbox = layerBBox;
|
||||
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update BBOX for Layer [" + getName() + "]");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[LAYER]",
|
||||
"Fail to update BBOX for Layer [" + getName() + "] :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class ImgCacheLayer {
|
||||
private Layer layer;
|
||||
private String layerStyle = "DEFAULT";
|
||||
private File cacheDir;
|
||||
private CacheFormat cacheFormat = new CacheFormat();
|
||||
private CacheLevelSet levelSet;
|
||||
|
||||
public ImgCacheLayer(String name, String style) throws Exception {
|
||||
this.layer = ServerContext.getMap().getLayer(name);
|
||||
if (!ServerUtil.isNullString((String)style)) {
|
||||
this.layerStyle = style;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLayerName() {
|
||||
return this.layer.getName();
|
||||
}
|
||||
|
||||
public String getLayerStyle() {
|
||||
return this.layerStyle;
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return this.layer.getBBox();
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
return this.layer.getCRS();
|
||||
}
|
||||
|
||||
public File getCacheDir() {
|
||||
return this.cacheDir;
|
||||
}
|
||||
|
||||
public void setCacheFormat(CacheFormat format) {
|
||||
if (format != null) {
|
||||
this.cacheFormat = format;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCacheSizeW() {
|
||||
return this.cacheFormat.getWidth();
|
||||
}
|
||||
|
||||
public int getCacheSizeH() {
|
||||
return this.cacheFormat.getHeight();
|
||||
}
|
||||
|
||||
public String getCacheFormat() {
|
||||
return this.cacheFormat.getFormat();
|
||||
}
|
||||
|
||||
public CacheLevelSet getCacheLevelSet() {
|
||||
return this.levelSet;
|
||||
}
|
||||
|
||||
public void setCacheDir(File dir) throws IOException {
|
||||
this.cacheDir = new File(dir, this.layer.getName());
|
||||
if (!this.cacheDir.exists() && !this.cacheDir.mkdirs()) {
|
||||
throw new IOException("Can't access CacheLocation for this layer [" + this.cacheDir.getAbsolutePath() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public void setCacheLevelSet(CacheLevelSet lSet) throws Exception {
|
||||
this.levelSet = lSet;
|
||||
this.levelSet.refindCacheLevelSet(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,264 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.management.modelmbean.XMLParseException;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.jdom.Attribute;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.input.SAXBuilder;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class ImgCacheMngr {
|
||||
private static ConcurrentHashMap<String, ImgCacheLayer> cacheLayerStore = new ConcurrentHashMap();
|
||||
private static ConcurrentHashMap<String, ImgCacheLayer> dirtyCacheLayerStore;
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static void initLayers() {
|
||||
ConcurrentHashMap<String, ImgCacheLayer> concurrentHashMap = cacheLayerStore = new ConcurrentHashMap();
|
||||
synchronized (concurrentHashMap) {
|
||||
try {
|
||||
File confFile = new File(ServerContext.getPluginsFolder(), String.valueOf(ServerContext.getMap().getName()) + ".IMGCACHE");
|
||||
if (!confFile.exists()) {
|
||||
throw new IOException("Configuration file is not exist :: " + confFile.getAbsolutePath());
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[IMGCACHE]", "Now create [" + ServerContext.getMap().getName() + "] ImgCache Layer");
|
||||
AVList params = ImgCacheMngr.parseImgCacheLayer(confFile);
|
||||
File cacheDir = (File)params.getValue("img.cache.conf.cache.location");
|
||||
CacheFormat cacheFormat = (CacheFormat)params.getValue("img.cache.conf.cache.format");
|
||||
CacheLevelSet cacheLevelSet = (CacheLevelSet)params.getValue("img.cache.conf.cache.levelset");
|
||||
ArrayList<ImgCacheLayer> layers = (ArrayList)params.getValue("img.cache.conf.layers");
|
||||
for (ImgCacheLayer layer : layers) {
|
||||
try {
|
||||
layer.setCacheDir(cacheDir);
|
||||
layer.setCacheFormat(cacheFormat);
|
||||
layer.setCacheLevelSet(cacheLevelSet.copy());
|
||||
cacheLayerStore.put(layer.getLayerName(), layer);
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "[" + layer.getLayerName() + "] Add ImgCache Layer Success");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[IMGCACHE]", "[" + layer.getLayerName() + "] Add ImgCache Layer Fail :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (cacheLayerStore.size() == 0) {
|
||||
LogMngr.getInstance().logError("[IMGCACHE]", "Create ImgCache Layer Fail :: Layer Count is [0]");
|
||||
} else {
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "Create ImgCache Layer Success :: Layer Count is [" + cacheLayerStore.size() + "]");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[IMGCACHE]", "Create ImgCache Layer Fail :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AVList parseImgCacheLayer(File xml) throws Exception {
|
||||
LogMngr.getInstance().logDebug("[IMGCACHE]", "[" + xml.getName() + "] Parse ImgCache Layer");
|
||||
SAXBuilder builder = new SAXBuilder();
|
||||
Document doc = builder.build(xml);
|
||||
Element root = doc.getRootElement();
|
||||
if (!root.getName().equalsIgnoreCase("IMAGE_CACHE")) {
|
||||
throw new XMLParseException(String.valueOf(xml.getName()) + " > Has no tag <IMAGE_CACHE>");
|
||||
}
|
||||
AVList params = new AVList();
|
||||
for (Object child : root.getChildren()) {
|
||||
if (!(child instanceof Element)) continue;
|
||||
Element element = (Element)child;
|
||||
if (element.getName().equalsIgnoreCase("LAYERS")) {
|
||||
params.setValue("img.cache.conf.layers", ImgCacheMngr.parseLayers(element));
|
||||
continue;
|
||||
}
|
||||
if (element.getName().equalsIgnoreCase("CACHELOCATION")) {
|
||||
params.setValue("img.cache.conf.cache.location", (Object)ImgCacheMngr.parseLoc(element));
|
||||
continue;
|
||||
}
|
||||
if (element.getName().equalsIgnoreCase("CACHEFORMAT")) {
|
||||
CacheFormat cFormat = new CacheFormat();
|
||||
for (Object attr : element.getAttributes()) {
|
||||
if (!(attr instanceof Attribute)) continue;
|
||||
Attribute tileformatAttr = (Attribute)attr;
|
||||
if (tileformatAttr.getName().equalsIgnoreCase("WIDTH")) {
|
||||
cFormat.setWidth(Integer.parseInt(tileformatAttr.getValue().trim()));
|
||||
continue;
|
||||
}
|
||||
if (tileformatAttr.getName().equalsIgnoreCase("HEIGHT")) {
|
||||
cFormat.setHeight(Integer.parseInt(tileformatAttr.getValue().trim()));
|
||||
continue;
|
||||
}
|
||||
if (!tileformatAttr.getName().equalsIgnoreCase("FORMAT")) continue;
|
||||
cFormat.setFormat(tileformatAttr.getValue().trim());
|
||||
}
|
||||
params.setValue("img.cache.conf.cache.format", (Object)cFormat);
|
||||
continue;
|
||||
}
|
||||
if (!element.getName().equalsIgnoreCase("LEVELSET")) continue;
|
||||
CacheLevelSet lvlSet = new CacheLevelSet();
|
||||
for (Object level : element.getChildren()) {
|
||||
Element levelElement;
|
||||
if (!(level instanceof Element) || !(levelElement = (Element)level).getName().equalsIgnoreCase("LEVEL")) continue;
|
||||
lvlSet.addLevel(ImgCacheMngr.parseLevel(levelElement));
|
||||
}
|
||||
params.setValue("img.cache.conf.cache.levelset", (Object)lvlSet);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
private static CacheLevel parseLevel(Element ele) throws Exception {
|
||||
Integer level = null;
|
||||
Double resoltution = null;
|
||||
Double scale = null;
|
||||
for (Object attr : ele.getAttributes()) {
|
||||
if (!(attr instanceof Attribute)) continue;
|
||||
Attribute matrixAttr = (Attribute)attr;
|
||||
if (matrixAttr.getName().equalsIgnoreCase("LEVEL")) {
|
||||
level = Integer.parseInt(matrixAttr.getValue().trim());
|
||||
continue;
|
||||
}
|
||||
if (matrixAttr.getName().equalsIgnoreCase("RESOLUTION")) {
|
||||
resoltution = Double.parseDouble(matrixAttr.getValue().trim());
|
||||
continue;
|
||||
}
|
||||
if (!matrixAttr.getName().equalsIgnoreCase("SCALE")) continue;
|
||||
scale = Double.parseDouble(matrixAttr.getValue().trim());
|
||||
}
|
||||
if (level == null) {
|
||||
throw new XMLParseException("<MATRIX> Attribute value [LAVEL] is null.");
|
||||
}
|
||||
if (resoltution == null && scale == null) {
|
||||
throw new XMLParseException("<MATRIX> Attribute value [RESOLUTION,SCALE] is null.");
|
||||
}
|
||||
return new CacheLevel(level, resoltution, scale);
|
||||
}
|
||||
|
||||
private static ReferencedEnvelope parseExtent(Element bbox) throws Exception {
|
||||
String crsName = null;
|
||||
for (Object attr : bbox.getAttributes()) {
|
||||
Attribute bboxAttr;
|
||||
if (!(attr instanceof Attribute) || !(bboxAttr = (Attribute)attr).getName().equalsIgnoreCase("CRS")) continue;
|
||||
crsName = bboxAttr.getValue().trim().toUpperCase();
|
||||
}
|
||||
CoordinateReferenceSystem crs = CRSMngr.getCRS(crsName);
|
||||
if (crs == null) {
|
||||
throw new XMLParseException("<" + bbox.getName() + "> Attribute value [CRS] is Not Available. :: [" + crsName + "] is not Exists.");
|
||||
}
|
||||
double minX = 0.0;
|
||||
double minY = 0.0;
|
||||
double maxX = 0.0;
|
||||
double maxY = 0.0;
|
||||
for (Object subChild : bbox.getChildren()) {
|
||||
String[] coord;
|
||||
if (!(subChild instanceof Element)) continue;
|
||||
Element subElement = (Element)subChild;
|
||||
if (subElement.getName().equalsIgnoreCase("LOWERCORNER")) {
|
||||
coord = subElement.getTextTrim().split(",");
|
||||
if (coord.length != 2) {
|
||||
coord = subElement.getTextTrim().split("\\s+");
|
||||
}
|
||||
if (coord.length != 2) {
|
||||
throw new XMLParseException("<LOWERCORNER> value is Not Coordinate. :: " + subElement.getText());
|
||||
}
|
||||
minX = Double.parseDouble(coord[0]);
|
||||
minY = Double.parseDouble(coord[1]);
|
||||
continue;
|
||||
}
|
||||
if (!subElement.getName().equalsIgnoreCase("UPPERCORNER")) continue;
|
||||
coord = subElement.getTextTrim().split(",");
|
||||
if (coord.length != 2) {
|
||||
coord = subElement.getTextTrim().split("\\s+");
|
||||
}
|
||||
if (coord.length != 2) {
|
||||
throw new XMLParseException("<UPPERCORNER> value is Not Coordinate. :: " + subElement.getText());
|
||||
}
|
||||
maxX = Double.parseDouble(coord[0]);
|
||||
maxY = Double.parseDouble(coord[1]);
|
||||
}
|
||||
return new ReferencedEnvelope(minX, maxX, minY, maxY, crs);
|
||||
}
|
||||
|
||||
private static File parseLoc(Element ele) throws IOException {
|
||||
File dir = new File(ele.getTextTrim());
|
||||
if (dir.exists()) {
|
||||
for (Object attr : ele.getAttributes()) {
|
||||
Attribute layerAttr;
|
||||
if (!(attr instanceof Attribute) || !(layerAttr = (Attribute)attr).getName().equalsIgnoreCase("CLEARBEFORE") || !ServerUtil.getBooleanValue((String)layerAttr.getValue())) continue;
|
||||
ServerUtil.removeFile((File)dir, (boolean)true);
|
||||
}
|
||||
} else if (!dir.mkdirs()) {
|
||||
throw new IOException("Can't access CacheLocation [" + dir.getAbsolutePath() + "]");
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
private static ArrayList<ImgCacheLayer> parseLayers(Element ele) throws IOException {
|
||||
ArrayList<ImgCacheLayer> layers = new ArrayList<ImgCacheLayer>();
|
||||
for (Object child : ele.getChildren()) {
|
||||
Element layer;
|
||||
if (!(child instanceof Element) || !(layer = (Element)child).getName().equalsIgnoreCase("LAYER")) continue;
|
||||
String name = null;
|
||||
String style = "DEFAULT";
|
||||
for (Object attr : layer.getAttributes()) {
|
||||
if (!(attr instanceof Attribute)) continue;
|
||||
Attribute layerAttr = (Attribute)attr;
|
||||
if (layerAttr.getName().equalsIgnoreCase("NAME")) {
|
||||
name = layerAttr.getValue().trim();
|
||||
continue;
|
||||
}
|
||||
if (!layerAttr.getName().equalsIgnoreCase("STYLE")) continue;
|
||||
style = layerAttr.getValue().trim();
|
||||
}
|
||||
try {
|
||||
layers.add(new ImgCacheLayer(name, style));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[IMGCACHE]", "Layer name [" + name + "] has problem :: " + e);
|
||||
}
|
||||
}
|
||||
if (layers.size() == 0) {
|
||||
throw new IOException("LAYER count is zero.");
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
try {
|
||||
dirtyCacheLayerStore = cacheLayerStore;
|
||||
ImgCacheMngr.initLayers();
|
||||
dirtyCacheLayerStore.clear();
|
||||
dirtyCacheLayerStore = null;
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "Success to reload ImgCache Layer.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[IMGCACHE]", "Fail to reload ImgCache Layer. Now use previous ImgCache Layer :: " + e);
|
||||
cacheLayerStore = dirtyCacheLayerStore;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static ImgCacheLayer getImgCacheLayer(String id) throws Exception {
|
||||
if (ServerUtil.isNullString((String)id)) {
|
||||
throw new NullPointerException("ID value is NULL.");
|
||||
}
|
||||
ImgCacheLayer layer = cacheLayerStore.get(id.trim().toUpperCase());
|
||||
if (layer == null) {
|
||||
throw new NullPointerException("Layer [" + id.trim() + "] is not exist in ImageCache Service.");
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static void removeImgCache(String id) throws Exception {
|
||||
ConcurrentHashMap<String, ImgCacheLayer> concurrentHashMap = cacheLayerStore;
|
||||
synchronized (concurrentHashMap) {
|
||||
ImgCacheLayer layer = ImgCacheMngr.getImgCacheLayer(id);
|
||||
ServerUtil.removeFile((File)layer.getCacheDir(), (boolean)true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.opengis.filter.identity.FeatureId;
|
||||
|
||||
class InsertParams
|
||||
{
|
||||
public String sqlString;
|
||||
public Double maxValue;
|
||||
public ArrayList<FeatureId> featureIDs = new ArrayList();
|
||||
|
||||
public InsertParams(String sql, Double max) {
|
||||
this.sqlString = sql;
|
||||
this.maxValue = max;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.geotools.se.v1_1.SE;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ColorMapEntry;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.xml.AbstractComplexBinding;
|
||||
import org.geotools.xml.ElementInstance;
|
||||
import org.geotools.xml.Node;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
|
||||
public class InterpolateBinding110 extends AbstractComplexBinding
|
||||
{
|
||||
StyleFactory styleFactory;
|
||||
FilterFactory filterFactory;
|
||||
|
||||
public InterpolateBinding110(StyleFactory styleFactory, FilterFactory filterFactory)
|
||||
{
|
||||
this.styleFactory = styleFactory;
|
||||
this.filterFactory = filterFactory;
|
||||
}
|
||||
|
||||
public QName getTarget()
|
||||
{
|
||||
return SE.Interpolate;
|
||||
}
|
||||
|
||||
public Class getType()
|
||||
{
|
||||
return ColorMap.class;
|
||||
}
|
||||
|
||||
public Object parse(ElementInstance instance, Node node, Object value)
|
||||
throws Exception
|
||||
{
|
||||
ColorMap map = this.styleFactory.createColorMap();
|
||||
|
||||
List<Node>children = node.getChildren("InterpolationPoint");
|
||||
for (Node child : children)
|
||||
{
|
||||
ColorMapEntry entry = this.styleFactory.createColorMapEntry();
|
||||
|
||||
double quantity = Double.parseDouble(child.getChildValue("Data").toString());
|
||||
entry.setQuantity(this.filterFactory.literal(quantity));
|
||||
|
||||
String colorStr = child.getChildValue("Value").toString();
|
||||
Color color = ServerUtil.getColorFromHex(colorStr);
|
||||
double opacity = color.getAlpha() / 255.0D;
|
||||
entry.setOpacity(this.filterFactory.literal(String.format("%.2f", new Object[] { Double.valueOf(opacity) })));
|
||||
entry.setColor(this.filterFactory.literal(ServerUtil.getHexFromColor(color)));
|
||||
|
||||
map.addColorMapEntry(entry);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,465 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class JdbcStoreMngr {
|
||||
private static ConcurrentHashMap<String, JDBCDataStore> dataStores = new ConcurrentHashMap();
|
||||
private static ConcurrentHashMap<String, JDBCDataStore> dirtyDataStores;
|
||||
public static final String DEFAULT_PK_COLUMN = "GID";
|
||||
public static final Boolean DEFAULT_USE_SPATIAL;
|
||||
public static final int DEFAULT_MIN_CONN = 10;
|
||||
public static final int DEFAULT_MAX_CONN = 25;
|
||||
public static final int DEFAULT_FETCH_SIZE = 50;
|
||||
public static final int DEFAULT_CONN_TIMEOUT = 30;
|
||||
public static final int DEFAULT_PS_CACHE_SIZE = 100;
|
||||
public static final Boolean DEFAULT_EXPOSE_PK;
|
||||
|
||||
static {
|
||||
DEFAULT_USE_SPATIAL = true;
|
||||
DEFAULT_EXPOSE_PK = Boolean.TRUE;
|
||||
}
|
||||
|
||||
public static synchronized void initLayers() {
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Connections");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
JdbcStoreMngr.initDataStore();
|
||||
if (dataStores.size() == 0) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcLayer :: JdbcDataStore size is ZERO[0]");
|
||||
return;
|
||||
}
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Layers");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
JdbcStoreMngr.initJdbcLayer();
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
private static void initDataStore() {
|
||||
dataStores = new ConcurrentHashMap();
|
||||
Connection conn = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||
synchronized (concurrentHashMap) {
|
||||
block20: {
|
||||
try {
|
||||
try {
|
||||
conn = ConnMngr.getInstance().openConn();
|
||||
st = conn.createStatement();
|
||||
String sql = "SELECT * FROM O2MAP_SERVER_INFO";
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Load configuration info :: SQL> " + sql);
|
||||
rs = st.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
String sName = rs.getString("SERVER_NAME").trim().toUpperCase();
|
||||
String sType = rs.getString("SERVER_TYPE").trim().toUpperCase();
|
||||
String sIP = rs.getString("SERVER_IP".trim());
|
||||
String sPort = rs.getString("SERVER_PORT").trim();
|
||||
String database = rs.getString("DATABASE_NAME").trim();
|
||||
String dbUser = rs.getString("DB_USER").trim();
|
||||
String dbPass = rs.getString("DB_PASSWD").trim();
|
||||
if (ServerContext.isEncryption()) {
|
||||
sIP = EncryptUtil.decrypt((String)sIP, (String)"wldhxn");
|
||||
sPort = EncryptUtil.decrypt((String)sPort, (String)"wldhxn");
|
||||
database = EncryptUtil.decrypt((String)database, (String)"wldhxn");
|
||||
dbUser = EncryptUtil.decrypt((String)dbUser, (String)"wldhxn");
|
||||
dbPass = EncryptUtil.decrypt((String)dbPass, (String)"wldhxn");
|
||||
}
|
||||
String pkCol = DEFAULT_PK_COLUMN;
|
||||
String tStr = rs.getString("PK_COLUMN");
|
||||
if (tStr != null) {
|
||||
pkCol = tStr.trim().toUpperCase();
|
||||
}
|
||||
boolean useSpatial = DEFAULT_USE_SPATIAL;
|
||||
tStr = rs.getString("USE_SPATIAL").trim();
|
||||
if (!ServerUtil.isNullString((String)tStr) && tStr.equalsIgnoreCase("N")) {
|
||||
useSpatial = false;
|
||||
}
|
||||
int minConn = 10;
|
||||
try {
|
||||
minConn = Integer.parseInt(rs.getString("MIN_CONN"));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
int maxConn = 25;
|
||||
try {
|
||||
maxConn = Integer.parseInt(rs.getString("MAX_CONN"));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
int fetchSize = 50;
|
||||
try {
|
||||
fetchSize = Integer.parseInt(rs.getString("FETCH_SIZE"));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put(O2DSFactory.DBTYPE.key, sType);
|
||||
params.put(O2DSFactory.HOST.key, sIP);
|
||||
params.put(O2DSFactory.PORT.key, Integer.valueOf(sPort));
|
||||
params.put(O2DSFactory.DATABASE.key, database);
|
||||
params.put(O2DSFactory.USER.key, dbUser);
|
||||
params.put(O2DSFactory.PASSWD.key, dbPass);
|
||||
params.put(O2DSFactory.MINCONN.key, minConn);
|
||||
params.put(O2DSFactory.MAXCONN.key, maxConn);
|
||||
params.put(O2DSFactory.MAXWAIT.key, 30);
|
||||
params.put(O2DSFactory.VALIDATECONN.key, Boolean.FALSE);
|
||||
params.put(O2DSFactory.FETCHSIZE.key, fetchSize);
|
||||
params.put(O2DSFactory.MAX_OPEN_PREPARED_STATEMENTS.key, 100);
|
||||
params.put(O2DSFactory.EXPOSE_PK.key, DEFAULT_EXPOSE_PK);
|
||||
params.put(O2DSFactory.NAMESPACE.key, ServerContext.getMap().getNameSpaceURI());
|
||||
params.put(O2DSFactory.O2_SERVER_NAME.key, sName);
|
||||
params.put(O2DSFactory.O2_PK_COLUMN_NAME.key, pkCol);
|
||||
params.put(O2DSFactory.O2_USE_SPATIAL.key, useSpatial);
|
||||
try {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Crate Jdbc DataStore :: " + params);
|
||||
JDBCDataStore ds = new O2DSFactory(params).getDataStore();
|
||||
ds.getTypeNames();
|
||||
dataStores.put(sName, ds);
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Success to add Jdbc DataStore [" + sName + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to add Jdbc DataStore [" + sName + "] :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcDataStore :: " + e);
|
||||
LogMngr.getInstance().logError("[JDBC]", "Please find and check O2MAP_SERVER_INFO table");
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
break block20;
|
||||
}
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
throw throwable;
|
||||
}
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initJdbcLayer() {
|
||||
block35: {
|
||||
Connection connection = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
try {
|
||||
if (ServerContext.getMap().getServiceLayerSet().getLayers().size() != 0) {
|
||||
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
||||
LogMngr.getInstance().logWarn("[JDBC]", "* This ServiceMap [" + ServerContext.getMap().getName() + "] already has service layers [" + ServerContext.getMap().getServiceLayerSet().getLayers().size() + "]");
|
||||
LogMngr.getInstance().logWarn("[JDBC]", "* JdbcLayer does not allow duplicate service. please check this.");
|
||||
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
||||
}
|
||||
connection = ConnMngr.getInstance().openConn();
|
||||
stmt = connection.createStatement();
|
||||
String sql = "SELECT * FROM O2MAP_SERVICE_INFO";
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Load layers info :: SQL > " + sql);
|
||||
rs = stmt.executeQuery(sql);
|
||||
int count = 0;
|
||||
ArrayList<AVList> grpList = new ArrayList<AVList>();
|
||||
if (rs != null) {
|
||||
while (rs.next()) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "");
|
||||
String mapName = rs.getString("MAP_NAME");
|
||||
if (ServerUtil.isNullString((String)mapName)) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME is NULL");
|
||||
continue;
|
||||
}
|
||||
if (!mapName.trim().equalsIgnoreCase(ServerContext.getMap().getName())) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME [" + mapName + "] is not equal ServiceMapName [" + ServerContext.getMap().getName() + "]");
|
||||
continue;
|
||||
}
|
||||
String layerName = rs.getString("LAYER_NAME");
|
||||
String layerType = rs.getString("LAYER_TYPE");
|
||||
String refServer = rs.getString("REF_SERVER");
|
||||
String refSource = rs.getString("REF_SOURCE");
|
||||
String refSrid = rs.getString("REF_SRID");
|
||||
String useCache = rs.getString("USE_CACHE");
|
||||
String desc = rs.getString("DESCRIPTION");
|
||||
StyledLayerDescriptor sld = null;
|
||||
try {
|
||||
is = rs.getBinaryStream("SLD");
|
||||
byte[] bytes = ServerUtil.cloneInputStream((InputStream)is);
|
||||
ByteArrayInputStream cloneIs = new ByteArrayInputStream(bytes);
|
||||
sld = StyleMngr.parseSLD((InputStream)cloneIs);
|
||||
}
|
||||
catch (Exception se) {
|
||||
sld = null;
|
||||
}
|
||||
Date lastUpdate = null;
|
||||
try {
|
||||
lastUpdate = rs.getDate("LAST_UPDATE");
|
||||
}
|
||||
catch (Exception de) {
|
||||
try {
|
||||
Timestamp stamp = rs.getTimestamp("LAST_UPDATE");
|
||||
lastUpdate = new Date(stamp.getTime());
|
||||
}
|
||||
catch (Exception se) {
|
||||
lastUpdate = null;
|
||||
}
|
||||
}
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", (Object)mapName);
|
||||
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||
params.setValue("conf.service.ref.server", (Object)refServer);
|
||||
params.setValue("conf.service.ref.source", (Object)refSource);
|
||||
params.setValue("conf.service.ref.srid", (Object)refSrid);
|
||||
params.setValue("conf.service.sld", (Object)sld);
|
||||
if (ServerUtil.getBooleanValue((String)useCache)) {
|
||||
params.setValue("conf.service.use.cache", (Object)true);
|
||||
} else {
|
||||
params.setValue("conf.service.use.cache", (Object)false);
|
||||
}
|
||||
params.setValue("conf.service.last.update", (Object)lastUpdate);
|
||||
params.setValue("conf.service.description", (Object)desc);
|
||||
try {
|
||||
Layer layer = null;
|
||||
if (layerType.equalsIgnoreCase("FEA")) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Create FeatureLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||
if (ServerUtil.isNullString((String)refServer)) {
|
||||
throw new Exception("REF_SERVER value is NULL.");
|
||||
}
|
||||
if (JdbcStoreMngr.getDataStore(refServer) == null) {
|
||||
throw new Exception("REF_SERVER [" + refServer + "] is not exists.");
|
||||
}
|
||||
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.JDBC, (AVList)params);
|
||||
} else {
|
||||
if (layerType.equalsIgnoreCase("GRP")) {
|
||||
grpList.add(params);
|
||||
continue;
|
||||
}
|
||||
if (layerType.equalsIgnoreCase("WMS")) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Create ImageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.WMS, (AVList)params);
|
||||
} else if (layerType.equalsIgnoreCase("WCS")) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Create CoverageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.WCS, (AVList)params);
|
||||
}
|
||||
}
|
||||
if (layer == null) {
|
||||
throw new Exception("Layer object is NULL.");
|
||||
}
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
++count;
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Add Layer Success :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Add Layer Fail :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
while (i < grpList.size()) {
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "Create GroupLayer :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||
try {
|
||||
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.GROUP, (AVList)((AVList)grpList.get(i)));
|
||||
if (layer == null) {
|
||||
throw new Exception("Layer object is NULL.");
|
||||
}
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
++count;
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Add Layer Success :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Add Layer Fail :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[JDBC]", "");
|
||||
if (count == 0) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Create JdbcLayer Fail :: JdbcLayer size is ZERO[0]");
|
||||
} else {
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Create JdbcLayer Success :: JdbcLayer Count is [" + count + "]");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcLayer :: " + e);
|
||||
LogMngr.getInstance().logError("[JDBC]", "Please find and check O2MAP_SERVICE_INFO table");
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(stmt);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
break block35;
|
||||
}
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(stmt);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
throw throwable;
|
||||
}
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(stmt);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
}
|
||||
}
|
||||
|
||||
public static FeatureLayer addLayer(String storeName, String layerName, String layerSource, String crsCode, String desc) throws Exception {
|
||||
JDBCDataStore store = JdbcStoreMngr.getDataStore(storeName);
|
||||
if (store == null) {
|
||||
throw new IOException("JdbcLayer DataStore is not exist [" + storeName + "]");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)layerName)) {
|
||||
throw new IOException("JdbcLayer LayerName is null");
|
||||
}
|
||||
if (ServerContext.getMap().getServiceLayerSet().isExistLayer(layerName)) {
|
||||
throw new IOException("JdbcLayer LayerName [" + layerName + "] is already exist");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)layerSource)) {
|
||||
throw new IOException("JdbcLayer LayerSource is null");
|
||||
}
|
||||
layerSource = layerSource.trim().toUpperCase();
|
||||
List<String> layers = Arrays.asList(store.getTypeNames());
|
||||
if (!layers.contains(layerSource)) {
|
||||
throw new IOException("JdbcLayer LayerSource [" + layerSource + "] is not exist in this JdbcDataStore [" + storeName + "]");
|
||||
}
|
||||
CoordinateReferenceSystem crs = CRSMngr.getCRS((String)crsCode, (boolean)true);
|
||||
if (crs == null) {
|
||||
crs = CRS.decode((String)"4326");
|
||||
}
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||
params.setValue("conf.service.ref.server", (Object)storeName);
|
||||
params.setValue("conf.service.ref.source", (Object)layerSource);
|
||||
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||
params.setValue("conf.service.sld", null);
|
||||
params.setValue("conf.service.use.cache", (Object)false);
|
||||
params.setValue("conf.service.last.update", null);
|
||||
params.setValue("conf.service.description", (Object)desc);
|
||||
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.JDBC, (AVList)params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
return (FeatureLayer)layer;
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC);
|
||||
try {
|
||||
dirtyDataStores = dataStores;
|
||||
JdbcStoreMngr.initLayers();
|
||||
JdbcStoreMngr.disposeDirtyDataStores();
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Success to reload JdbcStore.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to reload JdbcStore. Now use previous JdbcStore :: " + e);
|
||||
dataStores = dirtyDataStores;
|
||||
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static JDBCDataStore getDataStore(String storeName) throws Exception {
|
||||
if (ServerUtil.isNullString((String)storeName)) {
|
||||
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||
}
|
||||
if (dataStores.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return dataStores.get(storeName.trim().toUpperCase());
|
||||
}
|
||||
|
||||
public static synchronized void disposeDirtyDataStores() {
|
||||
if (dirtyDataStores == null) {
|
||||
return;
|
||||
}
|
||||
for (JDBCDataStore store : dirtyDataStores.values()) {
|
||||
store.dispose();
|
||||
Object var1_1 = null;
|
||||
}
|
||||
dirtyDataStores.clear();
|
||||
dirtyDataStores = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static synchronized void disposeDataStores() {
|
||||
if (dataStores.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||
synchronized (concurrentHashMap) {
|
||||
for (String storeName : dataStores.keySet()) {
|
||||
JDBCDataStore store = dataStores.get(storeName);
|
||||
try {
|
||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
||||
store.dispose();
|
||||
store = null;
|
||||
dataStores.remove(storeName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public static synchronized boolean disposeDataStore(String storeName) {
|
||||
if (ServerUtil.isNullString((String)storeName)) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Parameter StoreName is NULL");
|
||||
return false;
|
||||
}
|
||||
if (dataStores.isEmpty()) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "DataStore is NULL");
|
||||
return false;
|
||||
}
|
||||
storeName = storeName.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||
synchronized (concurrentHashMap) {
|
||||
JDBCDataStore store = dataStores.get(storeName);
|
||||
if (store == null) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "DataStore [" + storeName + "] is not exist");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
||||
store.dispose();
|
||||
store = null;
|
||||
dataStores.remove(storeName);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to remove layer linked this DataStore :: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.feature.FeatureCollection;
|
||||
import org.geotools.geojson.feature.FeatureJSON;
|
||||
import org.geotools.geojson.geom.GeometryJSON;
|
||||
|
||||
public class JsonUtil {
|
||||
public static void writeToResponse(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
FeatureJSON fJson = new FeatureJSON(new GeometryJSON(8));
|
||||
try {
|
||||
fJson.writeFeatureCollection((FeatureCollection)collection, (Object)writer);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new Exception("Failed to create json. " + e);
|
||||
}
|
||||
String json = writer.toString();
|
||||
try {
|
||||
resp.setContentType("application/json; charset=UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentLength(json.getBytes("UTF-8").length);
|
||||
resp.setStatus(200);
|
||||
resp.getWriter().write(json);
|
||||
resp.getWriter().flush();
|
||||
resp.getWriter().close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new Exception("Failed to write response. " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.gishur.core.ListItem;
|
||||
import org.gishur.core.SimpleList;
|
||||
import org.gishur.x.XPoint;
|
||||
import org.gishur.x.XPolygon;
|
||||
import org.gishur.x.XSegment;
|
||||
import org.gishur.x.voronoi.Skeleton;
|
||||
|
||||
public class KLISLabelUtil {
|
||||
private XPolygon polygon = null;
|
||||
private int xOffset = 0;
|
||||
private int yOffset = 0;
|
||||
private Point2D center = null;
|
||||
private double maxRadius = 0.0;
|
||||
private int edgediff = 0;
|
||||
private int hasParabola = 0;
|
||||
|
||||
public KLISLabelUtil(Polygon poly) {
|
||||
this.polygon = this.ConvertPloygon2XGeometry(poly);
|
||||
}
|
||||
|
||||
private XPolygon ConvertPloygon2XGeometry(Polygon poly) {
|
||||
if (poly.getNumInteriorRing() != 0) {
|
||||
return null;
|
||||
}
|
||||
ArrayList<Coordinate> coords = new ArrayList<Coordinate>(Arrays.asList(poly.getExteriorRing().getCoordinates()));
|
||||
this.xOffset = (int)coords.get((int)0).x / 100 * 100;
|
||||
this.yOffset = (int)coords.get((int)0).y / 100 * 100;
|
||||
ArrayList<XPoint> points = new ArrayList<XPoint>();
|
||||
int i = 0;
|
||||
while (i < coords.size()) {
|
||||
points.add(new XPoint(coords.get((int)i).x - (double)this.xOffset, coords.get((int)i).y - (double)this.yOffset));
|
||||
++i;
|
||||
}
|
||||
try {
|
||||
i = 0;
|
||||
while (i < points.size() - 2) {
|
||||
XPoint p1 = (XPoint)points.get(i);
|
||||
XPoint p2 = (XPoint)points.get(i + 1);
|
||||
XPoint p3 = (XPoint)points.get(i + 2);
|
||||
double ang1 = p1.angle(p2);
|
||||
double ang2 = p2.angle(p3);
|
||||
double angDiff = Math.abs(ang1 - ang2);
|
||||
int idff = (int)(angDiff * 180.0 / Math.PI);
|
||||
double dist = Point2D.distance(p1.x, p1.y, p2.x, p2.y);
|
||||
if (idff <= 3 || dist < 0.1) {
|
||||
points.remove(i + 1);
|
||||
--i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return new XPolygon(points.toArray(new XPoint[points.size()]));
|
||||
}
|
||||
catch (RuntimeException runtimeException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConvex() {
|
||||
if (this.polygon == null) {
|
||||
return false;
|
||||
}
|
||||
return this.polygon.convex();
|
||||
}
|
||||
|
||||
public Point2D GetMIC() {
|
||||
if (this.polygon == null) {
|
||||
return null;
|
||||
}
|
||||
Skeleton skeleton = new Skeleton(this.polygon);
|
||||
skeleton.execute();
|
||||
XPoint[] cpt = skeleton.MIC();
|
||||
if (cpt == null) {
|
||||
return null;
|
||||
}
|
||||
if (!this.polygon.contains(cpt[0].x, cpt[0].y)) {
|
||||
return null;
|
||||
}
|
||||
this.center = new Point2D.Double((double)this.xOffset + cpt[0].x, (double)this.yOffset + cpt[0].y);
|
||||
Point2D.Double ctp = new Point2D.Double((double)this.xOffset + cpt[1].x, (double)this.yOffset + cpt[1].y);
|
||||
this.maxRadius = Point2D.distance(this.center.getX(), this.center.getY(), ((Point2D)ctp).getX(), ((Point2D)ctp).getY());
|
||||
return this.center;
|
||||
}
|
||||
|
||||
public Point2D GetMIC_ex() {
|
||||
if (this.polygon == null) {
|
||||
return null;
|
||||
}
|
||||
Skeleton skeleton = new Skeleton(this.polygon);
|
||||
skeleton.execute();
|
||||
XPoint[] cpt = skeleton.MIC();
|
||||
if (cpt == null) {
|
||||
return null;
|
||||
}
|
||||
if (!this.polygon.contains(cpt[0].x, cpt[0].y)) {
|
||||
return null;
|
||||
}
|
||||
this.center = new Point2D.Double((double)this.xOffset + cpt[0].x, (double)this.yOffset + cpt[0].y);
|
||||
Point2D.Double ctp = new Point2D.Double((double)this.xOffset + cpt[1].x, (double)this.yOffset + cpt[1].y);
|
||||
this.maxRadius = Point2D.distance(this.center.getX(), this.center.getY(), ((Point2D)ctp).getX(), ((Point2D)ctp).getY());
|
||||
SimpleList skeletonPoints = skeleton.getLines(false);
|
||||
this.edgediff = Math.abs(skeletonPoints.length() - skeleton.getLines(true).length());
|
||||
if (skeletonPoints.length() == 1) {
|
||||
Object item = skeletonPoints.first().value();
|
||||
XPoint start = null;
|
||||
XPoint end = null;
|
||||
if (item instanceof XSegment) {
|
||||
start = ((XSegment)item).getStartPoint();
|
||||
end = ((XSegment)item).getEndPoint();
|
||||
} else {
|
||||
start = (XPoint)skeletonPoints.first().value();
|
||||
end = (XPoint)skeletonPoints.last().value();
|
||||
}
|
||||
this.center.setLocation((start.x + end.x) / 2.0, (end.x + end.y) / 2.0);
|
||||
return this.center;
|
||||
}
|
||||
boolean wasParabola = false;
|
||||
XPoint prevPt = new XPoint();
|
||||
double maxAngle = 0.0;
|
||||
double prevAngle = 0.0;
|
||||
ListItem listitem = skeletonPoints.first();
|
||||
while (listitem != null) {
|
||||
try {
|
||||
XSegment line = (XSegment)listitem.value();
|
||||
if (this.polygon.findPoint(line.source()) > 0 || this.polygon.findPoint(line.target()) > 0) {
|
||||
++this.edgediff;
|
||||
}
|
||||
if (wasParabola) {
|
||||
double dist = Point2D.distance(line.source().x, line.source().y, prevPt.x, prevPt.y);
|
||||
double diffAngle = Math.abs(prevAngle - line.angle());
|
||||
if (diffAngle > maxAngle && dist >= 0.5) {
|
||||
maxAngle = diffAngle;
|
||||
} else {
|
||||
--this.hasParabola;
|
||||
}
|
||||
}
|
||||
wasParabola = false;
|
||||
prevAngle = line.angle();
|
||||
prevPt.x = line.target().x;
|
||||
prevPt.y = line.target().y;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
wasParabola = true;
|
||||
++this.hasParabola;
|
||||
}
|
||||
listitem = listitem.next();
|
||||
}
|
||||
return this.center;
|
||||
}
|
||||
|
||||
public double getMaxRadius() {
|
||||
return this.maxRadius;
|
||||
}
|
||||
|
||||
public int edgeDiffCounts() {
|
||||
return this.edgediff;
|
||||
}
|
||||
|
||||
public int hasParabola() {
|
||||
return this.hasParabola;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,67 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
|
||||
import org.geotools.geometry.jts.LiteShape2;
|
||||
import org.geotools.renderer.label.LabelCacheItem;
|
||||
import org.geotools.renderer.style.TextStyle2D;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
import org.geotools.styling.TextSymbolizer.PolygonAlignOptions;
|
||||
|
||||
public class LabelCacheItemEx extends LabelCacheItem
|
||||
{
|
||||
private TextSymbolizer.PolygonAlignOptions polygonAlign = TextSymbolizer.PolygonAlignOptions.NONE;
|
||||
public static final String KEY_SPLIT_MULTIGEOMETRY = "splitMultiGeometry";
|
||||
private boolean isSplitMultiGeometry = false;
|
||||
public static final String KEY_MIN_FONT_SIZE = "minFontSize";
|
||||
private int minFontSize = 3;
|
||||
public static final String KEY_POLYGON_ALIGN_TEXT = "polygonAlignText";
|
||||
private PolygonAlignTextOptions polygonAlignText = PolygonAlignTextOptions.NONE;
|
||||
public static final String KEY_WRAP_TILE_TEXT = "wrapTileText";
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX = "textGraphicBox";
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_MARGIN = "textGraphicBox-margin";
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_FILL = "textGraphicBox-fill";
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_STROKE = "textGraphicBox-stroke";
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_STROKE_WIDTH = "textGraphicBox-strokeWidth";
|
||||
|
||||
public LabelCacheItemEx(String layerId, TextStyle2D textStyle, LiteShape2 shape, String label, TextSymbolizer symbolizer)
|
||||
{
|
||||
super(layerId, textStyle, shape, label, symbolizer);
|
||||
}
|
||||
|
||||
public void setPolygonAlignText(PolygonAlignTextOptions polygonAlign) {
|
||||
this.polygonAlignText = polygonAlign;
|
||||
}
|
||||
|
||||
public PolygonAlignTextOptions getPolygonAlignText() {
|
||||
return this.polygonAlignText;
|
||||
}
|
||||
|
||||
public void setPolygonAlign(TextSymbolizer.PolygonAlignOptions polygonAlign) {
|
||||
this.polygonAlign = polygonAlign;
|
||||
}
|
||||
|
||||
public TextSymbolizer.PolygonAlignOptions getPolygonAlign() {
|
||||
return this.polygonAlign;
|
||||
}
|
||||
|
||||
public void setMinFontSize(int size) {
|
||||
this.minFontSize = size;
|
||||
}
|
||||
|
||||
public int getMinFontSize() {
|
||||
return this.minFontSize;
|
||||
}
|
||||
|
||||
public void setSplitMultiGeometry(boolean split) {
|
||||
this.isSplitMultiGeometry = split;
|
||||
}
|
||||
|
||||
public boolean isSplitMultiGeometry() {
|
||||
return this.isSplitMultiGeometry;
|
||||
}
|
||||
|
||||
public static enum PolygonAlignTextOptions
|
||||
{
|
||||
NONE, MANUAL, ORTHO, MBR;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.awt.Font;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import org.geotools.renderer.label.LabelCacheItem;
|
||||
import org.geotools.renderer.style.TextStyle2D;
|
||||
|
||||
public class LabelInfo
|
||||
{
|
||||
public final LabelPainterEx labelPainter;
|
||||
public final Polygon polygon;
|
||||
public final GeneralPath generalPath;
|
||||
public final Font font;
|
||||
public final double anchorX;
|
||||
public final double anchorY;
|
||||
public final double displacementX;
|
||||
public final double displacementY;
|
||||
public Point2D center;
|
||||
public Point2D rCenter;
|
||||
public double rotation = 0.0D;
|
||||
|
||||
public LabelInfo(LabelPainterEx painter, Polygon poly, LabelCacheItemEx labelItem)
|
||||
{
|
||||
this.labelPainter = painter;
|
||||
|
||||
this.polygon = poly;
|
||||
this.generalPath = toGeneralPath(poly);
|
||||
|
||||
this.font = painter.getLabel().getTextStyle().getFont().deriveFont(new AffineTransform());
|
||||
|
||||
if (labelItem.getPolygonAlignText() == LabelCacheItemEx.PolygonAlignTextOptions.MANUAL)
|
||||
{
|
||||
this.anchorX = labelItem.getTextStyle().getAnchorX();
|
||||
this.anchorY = labelItem.getTextStyle().getAnchorY();
|
||||
this.displacementX = labelItem.getTextStyle().getDisplacementX();
|
||||
this.displacementY = labelItem.getTextStyle().getDisplacementY();
|
||||
|
||||
this.rotation = labelItem.getTextStyle().getRotation();
|
||||
if ((Double.isNaN(this.rotation)) ||
|
||||
(Double.isInfinite(this.rotation)))
|
||||
this.rotation = 0.0D;
|
||||
else {
|
||||
this.rotation = Math.toRadians(this.rotation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.anchorX = 0.5D;
|
||||
this.anchorY = 0.5D;
|
||||
this.displacementX = 0.0D;
|
||||
this.displacementY = 0.0D;
|
||||
}
|
||||
}
|
||||
|
||||
private GeneralPath toGeneralPath(Polygon polygon)
|
||||
{
|
||||
GeneralPath path = new GeneralPath();
|
||||
|
||||
Coordinate[] shell = polygon.getExteriorRing().getCoordinates();
|
||||
path.moveTo(shell[0].x, shell[0].y);
|
||||
for (int i = 1; i < shell.length; i++) {
|
||||
path.lineTo(shell[i].x, shell[i].y);
|
||||
}
|
||||
int interiorRing = polygon.getNumInteriorRing();
|
||||
|
||||
for (int i = 0; i < interiorRing; i++) {
|
||||
Coordinate[] holes = polygon.getInteriorRingN(i).getCoordinates();
|
||||
path.moveTo(holes[0].x, holes[0].y);
|
||||
for (int j = 1; j < holes.length; j++)
|
||||
path.lineTo(holes[j].x, holes[j].y);
|
||||
}
|
||||
path.closePath();
|
||||
return path;
|
||||
}
|
||||
|
||||
public boolean isConvexPolygon()
|
||||
{
|
||||
Coordinate[] coords = this.polygon.getExteriorRing().getCoordinates();
|
||||
|
||||
int n = coords.length;
|
||||
if (n < 4) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean sign = false;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double dx1 = coords[((i + 2) % n)].x - coords[((i + 1) % n)].x;
|
||||
double dy1 = coords[((i + 2) % n)].y - coords[((i + 1) % n)].y;
|
||||
double dx2 = coords[i].x - coords[((i + 1) % n)].x;
|
||||
double dy2 = coords[i].y - coords[((i + 1) % n)].y;
|
||||
|
||||
double zcrossproduct = dx1 * dy2 - dy1 * dx2;
|
||||
|
||||
if (i == 0) {
|
||||
sign = zcrossproduct > 0.0D;
|
||||
}
|
||||
else if (sign != zcrossproduct > 0.0D) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,588 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphMetrics;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.LineBreakMeasurer;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.Rectangle2D.Double;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.text.Bidi;
|
||||
import java.text.BreakIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.Icon;
|
||||
import org.geotools.geometry.jts.LiteShape2;
|
||||
import org.geotools.geometry.jts.TransformedShape;
|
||||
import org.geotools.renderer.label.LabelCacheImpl;
|
||||
import org.geotools.renderer.label.LabelCacheImpl.LabelRenderingMode;
|
||||
import org.geotools.renderer.label.LabelCacheItem;
|
||||
import org.geotools.renderer.label.LabelCacheItem.GraphicResize;
|
||||
import org.geotools.renderer.label.LineStringCursor;
|
||||
import org.geotools.renderer.lite.StyledShapePainter;
|
||||
import org.geotools.renderer.style.GraphicStyle2D;
|
||||
import org.geotools.renderer.style.IconStyle2D;
|
||||
import org.geotools.renderer.style.MarkStyle2D;
|
||||
import org.geotools.renderer.style.Style2D;
|
||||
import org.geotools.renderer.style.TextStyle2D;
|
||||
|
||||
public class LabelPainterEx
|
||||
{
|
||||
static final double EPS = 1.0E-006D;
|
||||
StyledShapePainter shapePainter = new StyledShapePainter();
|
||||
LabelCacheItem labelItem;
|
||||
List<LineInfo> lines;
|
||||
public Graphics2D graphics;
|
||||
LabelCacheImpl.LabelRenderingMode labelRenderingMode;
|
||||
GeometryFactory gf = new GeometryFactory();
|
||||
Rectangle2D labelBounds;
|
||||
|
||||
public LabelPainterEx(Graphics2D graphics, LabelCacheImpl.LabelRenderingMode labelRenderingMode)
|
||||
{
|
||||
this.graphics = graphics;
|
||||
this.labelRenderingMode = labelRenderingMode;
|
||||
}
|
||||
|
||||
public void setLabel(LabelCacheItem labelItem)
|
||||
{
|
||||
this.labelItem = labelItem;
|
||||
labelItem.getTextStyle().setLabel(labelItem.getLabel());
|
||||
|
||||
this.labelBounds = null;
|
||||
this.lines = null;
|
||||
|
||||
String text = labelItem.getLabel();
|
||||
LineInfo line;
|
||||
if (((!text.contains("\n")) && (labelItem.getAutoWrap() <= 0)) ||
|
||||
(labelItem.isFollowLineEnabled())) {
|
||||
FontRenderContext frc = this.graphics.getFontRenderContext();
|
||||
TextLayout layout = new TextLayout(text, labelItem.getTextStyle().getFont(), frc);
|
||||
line = new LineInfo(text, layoutSentence(text, labelItem), layout);
|
||||
this.labelBounds = line.gv.getVisualBounds();
|
||||
normalizeBounds(this.labelBounds);
|
||||
this.lines = Collections.singletonList(line);
|
||||
return;
|
||||
}
|
||||
|
||||
String[] splitted = text.split("\\n");
|
||||
|
||||
this.lines = new ArrayList();
|
||||
int prevPosition;
|
||||
if (labelItem.getAutoWrap() <= 0)
|
||||
{
|
||||
String[] arrayOfString = splitted;
|
||||
for (int i = 0; i < splitted.length; i++) {
|
||||
FontRenderContext frc = this.graphics.getFontRenderContext();
|
||||
TextLayout layout = new TextLayout(splitted[i], labelItem.getTextStyle().getFont(), frc);
|
||||
LineInfo info = new LineInfo(splitted[i], layoutSentence(splitted[i], labelItem), layout);
|
||||
this.lines.add(info);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Map map = new HashMap();
|
||||
map.put(TextAttribute.FONT, labelItem.getTextStyle().getFont());
|
||||
|
||||
for (int i = 0; i < splitted.length; i++) {
|
||||
|
||||
AttributedString attributed = new AttributedString(splitted[i], map);
|
||||
AttributedCharacterIterator iter = ((AttributedString)attributed).getIterator();
|
||||
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(iter,
|
||||
BreakIterator.getWordInstance(), this.graphics.getFontRenderContext());
|
||||
BreakIterator breaks = BreakIterator.getWordInstance();
|
||||
breaks.setText(splitted[i]);
|
||||
|
||||
prevPosition = 0;
|
||||
while (lineMeasurer.getPosition() < iter.getEndIndex())
|
||||
{
|
||||
TextLayout layout = lineMeasurer.nextLayout(labelItem.getAutoWrap(), splitted[i].length(), true);
|
||||
int newPosition = prevPosition;
|
||||
|
||||
if (layout != null) {
|
||||
newPosition = lineMeasurer.getPosition();
|
||||
} else {
|
||||
int nextBoundary = breaks.following(prevPosition);
|
||||
if (nextBoundary == -1)
|
||||
newPosition = splitted[i].length();
|
||||
else {
|
||||
newPosition = nextBoundary;
|
||||
}
|
||||
AttributedCharacterIterator subIter = ((AttributedString)attributed).getIterator(null, prevPosition, newPosition);
|
||||
layout = new TextLayout(subIter, this.graphics.getFontRenderContext());
|
||||
lineMeasurer.setPosition(newPosition);
|
||||
}
|
||||
|
||||
String extracted = splitted[i].substring(prevPosition, newPosition).trim();
|
||||
if (!"".equals(extracted)) {
|
||||
LineInfo info = new LineInfo(extracted, layoutSentence(extracted, labelItem),
|
||||
layout);
|
||||
this.lines.add(info);
|
||||
}
|
||||
prevPosition = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double maxWidth = 0.0D;
|
||||
for (Object attributed = this.lines.iterator(); ((Iterator)attributed).hasNext(); ) {
|
||||
line = (LineInfo)((Iterator)attributed).next();
|
||||
maxWidth = Math.max(line.gv.getVisualBounds().getWidth(), maxWidth);
|
||||
}
|
||||
|
||||
double boundsY = 0.0D;
|
||||
double labelY = 0.0D;
|
||||
for (LineInfo info : this.lines) {
|
||||
Rectangle2D currBounds = info.gv.getVisualBounds();
|
||||
TextLayout layout = info.layout;
|
||||
|
||||
double minX = (maxWidth - currBounds.getWidth()) *
|
||||
labelItem.getTextStyle().getAnchorX() - currBounds.getMinX();
|
||||
info.x = minX;
|
||||
|
||||
if (this.labelBounds == null) {
|
||||
this.labelBounds = currBounds;
|
||||
boundsY = currBounds.getMinY() + layout.getAscent() + layout.getDescent() +
|
||||
layout.getLeading();
|
||||
} else {
|
||||
Rectangle2D translated = new Rectangle2D.Double(minX, boundsY, currBounds
|
||||
.getWidth(), currBounds.getHeight());
|
||||
boundsY += layout.getAscent() + layout.getDescent() + layout.getLeading();
|
||||
labelY += layout.getAscent() + layout.getDescent() + layout.getLeading();
|
||||
this.labelBounds = this.labelBounds.createUnion(translated);
|
||||
}
|
||||
info.y = labelY;
|
||||
}
|
||||
normalizeBounds(this.labelBounds);
|
||||
}
|
||||
|
||||
void normalizeBounds(Rectangle2D bounds)
|
||||
{
|
||||
if (bounds.isEmpty())
|
||||
bounds.setRect(bounds.getCenterX() - 1.0D, bounds.getCenterY() - 1.0D, 2.0D, 2.0D);
|
||||
}
|
||||
|
||||
GlyphVector layoutSentence(String label, LabelCacheItem item)
|
||||
{
|
||||
Font font = item.getTextStyle().getFont();
|
||||
char[] chars = label.toCharArray();
|
||||
int length = label.length();
|
||||
if (Bidi.requiresBidi(chars, 0, length)) {
|
||||
Bidi bidi = new Bidi(label, -2);
|
||||
if (bidi.isRightToLeft())
|
||||
return font.layoutGlyphVector(this.graphics.getFontRenderContext(), chars, 0, length,
|
||||
1);
|
||||
if (bidi.isMixed()) {
|
||||
String r = "";
|
||||
for (int i = 0; i < bidi.getRunCount(); i++) {
|
||||
String s1 = label.substring(bidi.getRunStart(i), bidi.getRunLimit(i));
|
||||
if (bidi.getRunLevel(i) % 2 == 0) {
|
||||
s1 = new StringBuffer(s1).reverse().toString();
|
||||
}
|
||||
r = r + s1;
|
||||
}
|
||||
char[] chars2 = r.toCharArray();
|
||||
return font.layoutGlyphVector(this.graphics.getFontRenderContext(), chars2, 0, length,
|
||||
1);
|
||||
}
|
||||
}
|
||||
return font.createGlyphVector(this.graphics.getFontRenderContext(), chars);
|
||||
}
|
||||
|
||||
public LabelCacheItem getLabel()
|
||||
{
|
||||
return this.labelItem;
|
||||
}
|
||||
|
||||
public double getLineHeight()
|
||||
{
|
||||
return ((LineInfo)this.lines.get(0)).gv.getVisualBounds().getHeight() - ((LineInfo)this.lines.get(0)).layout.getDescent();
|
||||
}
|
||||
|
||||
public double getAscent()
|
||||
{
|
||||
return ((LineInfo)this.lines.get(0)).layout.getAscent();
|
||||
}
|
||||
|
||||
public int getStraightLabelWidth()
|
||||
{
|
||||
return (int)Math.round(getLabelBounds().getWidth());
|
||||
}
|
||||
|
||||
public int getLineCount()
|
||||
{
|
||||
return this.lines.size();
|
||||
}
|
||||
|
||||
public Rectangle2D getFullLabelBounds()
|
||||
{
|
||||
Rectangle2D bounds = (Rectangle2D)getLabelBounds().clone();
|
||||
|
||||
int haloRadius = Math.round(this.labelItem.getTextStyle().getHaloFill() != null ? this.labelItem
|
||||
.getTextStyle().getHaloRadius() : 0.0F);
|
||||
bounds.add(bounds.getMinX() - haloRadius, bounds.getMinY() - haloRadius);
|
||||
bounds.add(bounds.getMaxX() + haloRadius, bounds.getMaxY() + haloRadius);
|
||||
|
||||
if (this.labelItem.getTextStyle().getGraphic() != null) {
|
||||
Rectangle2D area = this.labelItem.getTextStyle().getGraphicDimensions();
|
||||
|
||||
int[] margin = this.labelItem.getGraphicMargin();
|
||||
LabelCacheItem.GraphicResize mode = this.labelItem.getGraphicsResize();
|
||||
Rectangle2D shieldBounds;
|
||||
if (mode == LabelCacheItem.GraphicResize.STRETCH)
|
||||
{
|
||||
shieldBounds = applyMargins(margin, bounds);
|
||||
} else if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL)
|
||||
{
|
||||
double factor = 1.0D;
|
||||
if (bounds.getWidth() > bounds.getHeight())
|
||||
factor = bounds.getWidth() / area.getWidth();
|
||||
else {
|
||||
factor = bounds.getHeight() / area.getHeight();
|
||||
}
|
||||
double width = area.getWidth() * factor;
|
||||
double height = area.getHeight() * factor;
|
||||
shieldBounds = new Rectangle2D.Double(width / 2.0D + bounds.getMinX() - bounds.getWidth() / 2.0D,
|
||||
height / 2.0D + bounds.getMinY() - bounds.getHeight() / 2.0D, width, height);
|
||||
shieldBounds = applyMargins(margin, shieldBounds);
|
||||
}
|
||||
else {
|
||||
shieldBounds = new Rectangle2D.Double(-area.getWidth() / 2.0D + bounds.getMinX() -
|
||||
bounds.getWidth() / 2.0D, -area.getHeight() / 2.0D + bounds.getMinY() -
|
||||
bounds.getHeight() / 2.0D, area.getWidth(), area.getHeight());
|
||||
}
|
||||
|
||||
bounds = bounds.createUnion(shieldBounds);
|
||||
}
|
||||
|
||||
normalizeBounds(bounds);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Rectangle2D applyMargins(int[] margin, Rectangle2D bounds) {
|
||||
if (bounds != null) {
|
||||
double xmin = bounds.getMinX() - margin[3];
|
||||
double ymin = bounds.getMinY() - margin[0];
|
||||
double width = bounds.getWidth() + margin[1] + margin[3];
|
||||
double height = bounds.getHeight() + margin[0] + margin[2];
|
||||
return new Rectangle2D.Double(xmin, ymin, width, height);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public Rectangle2D getLabelBounds()
|
||||
{
|
||||
return this.labelBounds;
|
||||
}
|
||||
|
||||
public void paintStraightLabel(AffineTransform transform)
|
||||
throws Exception
|
||||
{
|
||||
AffineTransform oldTransform = this.graphics.getTransform();
|
||||
try
|
||||
{
|
||||
AffineTransform newTransform = new AffineTransform(oldTransform);
|
||||
newTransform.concatenate(transform);
|
||||
this.graphics.setTransform(newTransform);
|
||||
|
||||
Style2D graphic = this.labelItem.getTextStyle().getGraphic();
|
||||
if (graphic != null)
|
||||
{
|
||||
Rectangle2D rect = getFullLabelBounds();
|
||||
LiteShape2 tempShape = new LiteShape2(
|
||||
this.gf.createPoint(new Coordinate(rect.getCenterX(), rect.getCenterY())),
|
||||
null, null, false, false);
|
||||
|
||||
graphic = resizeGraphic(graphic);
|
||||
this.shapePainter.paint(this.graphics, tempShape, graphic, graphic.getMaxScale());
|
||||
}
|
||||
|
||||
if (this.labelItem.getTextStyle().getFont().getSize() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lines.size() == 1) {
|
||||
drawGlyphVector(((LineInfo)this.lines.get(0)).gv);
|
||||
}
|
||||
else
|
||||
{
|
||||
AffineTransform lineTx = new AffineTransform(transform);
|
||||
for (LineInfo line : this.lines) {
|
||||
lineTx.setTransform(transform);
|
||||
lineTx.translate(line.x, line.y);
|
||||
this.graphics.setTransform(lineTx);
|
||||
drawGlyphVector(line.gv);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.graphics.setTransform(oldTransform); } this.graphics.setTransform(oldTransform);
|
||||
}
|
||||
|
||||
private Style2D resizeGraphic(Style2D graphic)
|
||||
{
|
||||
LabelCacheItem.GraphicResize mode = this.labelItem.getGraphicsResize();
|
||||
|
||||
if ((mode == LabelCacheItem.GraphicResize.NONE) || (mode == null)) {
|
||||
return graphic;
|
||||
}
|
||||
|
||||
double width = this.labelBounds.getWidth();
|
||||
double height = this.labelBounds.getHeight();
|
||||
int[] margin = this.labelItem.getGraphicMargin();
|
||||
if (margin != null) {
|
||||
width += margin[1] + margin[3];
|
||||
height += margin[0] + margin[2];
|
||||
}
|
||||
width = Math.round(width);
|
||||
height = Math.round(height);
|
||||
|
||||
if ((width <= 0.0D) || (height <= 0.0D)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((graphic instanceof MarkStyle2D)) {
|
||||
MarkStyle2D mark = (MarkStyle2D)graphic;
|
||||
|
||||
Shape original = mark.getShape();
|
||||
Rectangle2D bounds = original.getBounds2D();
|
||||
MarkStyle2D resized = (MarkStyle2D)mark.clone();
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL) {
|
||||
if (width > height)
|
||||
resized.setSize(Math.round(bounds.getHeight() * width / bounds.getWidth()));
|
||||
else
|
||||
resized.setSize(height);
|
||||
}
|
||||
else
|
||||
{
|
||||
TransformedShape tss = new TransformedShape();
|
||||
tss.shape = original;
|
||||
tss.setTransform(AffineTransform.getScaleInstance(width / bounds.getWidth(), height / bounds.getHeight()));
|
||||
resized.setShape(tss);
|
||||
resized.setSize(height);
|
||||
}
|
||||
|
||||
return resized;
|
||||
}if ((graphic instanceof IconStyle2D)) {
|
||||
IconStyle2D iconStyle = (IconStyle2D)graphic;
|
||||
IconStyle2D resized = (IconStyle2D)iconStyle.clone();
|
||||
|
||||
Icon icon = iconStyle.getIcon();
|
||||
AffineTransform at;
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL)
|
||||
{
|
||||
double factor;
|
||||
if (width > height)
|
||||
factor = width / icon.getIconWidth();
|
||||
else {
|
||||
factor = height / icon.getIconHeight();
|
||||
}
|
||||
at = AffineTransform.getScaleInstance(factor, factor);
|
||||
}
|
||||
else {
|
||||
at = AffineTransform.getScaleInstance(width / icon.getIconWidth(), height / icon.getIconHeight());
|
||||
}
|
||||
|
||||
resized.setIcon(new TransformedIconEx(icon, at));
|
||||
return resized;
|
||||
}if ((graphic instanceof GraphicStyle2D)) {
|
||||
GraphicStyle2D gstyle = (GraphicStyle2D)graphic;
|
||||
GraphicStyle2D resized = (GraphicStyle2D)graphic.clone();
|
||||
BufferedImage image = gstyle.getImage();
|
||||
AffineTransform at;
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL)
|
||||
{
|
||||
double factor;
|
||||
if (width > height)
|
||||
factor = width / image.getWidth();
|
||||
else {
|
||||
factor = height / image.getHeight();
|
||||
}
|
||||
at = AffineTransform.getScaleInstance(factor, factor);
|
||||
}
|
||||
else {
|
||||
at = AffineTransform.getScaleInstance(width / image.getWidth(), height / image.getHeight());
|
||||
}
|
||||
|
||||
AffineTransformOp ato = new AffineTransformOp(at, 2);
|
||||
image = ato.filter(image, null);
|
||||
resized.setImage(image);
|
||||
return resized;
|
||||
}
|
||||
return graphic;
|
||||
}
|
||||
|
||||
private void drawGlyphVector(GlyphVector gv)
|
||||
{
|
||||
Shape outline = gv.getOutline();
|
||||
if (this.labelItem.getTextStyle().getHaloFill() != null) {
|
||||
configureHalo();
|
||||
this.graphics.draw(outline);
|
||||
}
|
||||
configureLabelStyle();
|
||||
|
||||
if (this.labelRenderingMode == LabelCacheImpl.LabelRenderingMode.STRING) {
|
||||
this.graphics.drawGlyphVector(gv, 0.0F, 0.0F);
|
||||
} else if (this.labelRenderingMode == LabelCacheImpl.LabelRenderingMode.OUTLINE) {
|
||||
this.graphics.fill(outline);
|
||||
} else {
|
||||
AffineTransform tx = this.graphics.getTransform();
|
||||
if ((Math.abs(tx.getShearX()) >= 1.0E-006D) || (Math.abs(tx.getShearY()) > 1.0E-006D))
|
||||
this.graphics.fill(outline);
|
||||
else
|
||||
this.graphics.drawGlyphVector(gv, 0.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHalo()
|
||||
{
|
||||
this.graphics.setPaint(this.labelItem.getTextStyle().getHaloFill());
|
||||
this.graphics.setComposite(this.labelItem.getTextStyle().getHaloComposite());
|
||||
float haloRadius = this.labelItem.getTextStyle().getHaloFill() != null ? this.labelItem.getTextStyle().getHaloRadius() : 0.0F;
|
||||
this.graphics.setStroke(new BasicStroke(2.0F * haloRadius, 1, 1));
|
||||
}
|
||||
|
||||
private void configureLabelStyle()
|
||||
{
|
||||
Paint fill = this.labelItem.getTextStyle().getFill();
|
||||
Composite comp = this.labelItem.getTextStyle().getComposite();
|
||||
if (fill == null) {
|
||||
fill = Color.BLACK;
|
||||
comp = AlphaComposite.getInstance(3, 1.0F);
|
||||
}
|
||||
|
||||
this.graphics.setPaint(fill);
|
||||
this.graphics.setComposite(comp);
|
||||
}
|
||||
|
||||
public void paintCurvedLabel(LineStringCursor cursor)
|
||||
{
|
||||
if (this.labelItem.getTextStyle().getFont().getSize() == 0) {
|
||||
return;
|
||||
}
|
||||
GlyphVector glyphVector = ((LineInfo)this.lines.get(0)).gv;
|
||||
AffineTransform oldTransform = this.graphics.getTransform();
|
||||
try
|
||||
{
|
||||
if ((!isLabelUpwards(cursor)) && (this.labelItem.isForceLeftToRightEnabled())) {
|
||||
LineStringCursor reverse = cursor.reverse();
|
||||
reverse.moveTo(cursor.getLineStringLength() - cursor.getCurrentOrdinate());
|
||||
cursor = reverse;
|
||||
}
|
||||
|
||||
double anchorY = getLinePlacementYAnchor();
|
||||
|
||||
double mid = cursor.getCurrentOrdinate();
|
||||
Coordinate c = new Coordinate();
|
||||
c = cursor.getCurrentPosition(c);
|
||||
this.graphics.setPaint(Color.BLACK);
|
||||
|
||||
double startOrdinate = mid - getStraightLabelWidth() / 2;
|
||||
if (startOrdinate < 0.0D)
|
||||
startOrdinate = 0.0D;
|
||||
cursor.moveTo(startOrdinate);
|
||||
int numGlyphs = glyphVector.getNumGlyphs();
|
||||
float nextAdvance = glyphVector.getGlyphMetrics(0).getAdvance() * 0.5F;
|
||||
Shape[] outlines = new Shape[numGlyphs];
|
||||
AffineTransform[] transforms = new AffineTransform[numGlyphs];
|
||||
for (int i = 0; i < numGlyphs; i++) {
|
||||
outlines[i] = glyphVector.getGlyphOutline(i);
|
||||
Point2D p = glyphVector.getGlyphPosition(i);
|
||||
float advance = nextAdvance;
|
||||
nextAdvance = i < numGlyphs - 1 ? glyphVector.getGlyphMetrics(i + 1).getAdvance() * 0.5F :
|
||||
0.0F;
|
||||
|
||||
c = cursor.getCurrentPosition(c);
|
||||
AffineTransform t = new AffineTransform();
|
||||
t.setToTranslation(c.x, c.y);
|
||||
t.rotate(cursor.getCurrentAngle());
|
||||
t.translate(-p.getX() - advance, -p.getY() + getLineHeight() * anchorY);
|
||||
transforms[i] = t;
|
||||
|
||||
cursor.moveTo(cursor.getCurrentOrdinate() + advance + nextAdvance);
|
||||
}
|
||||
|
||||
if (this.labelItem.getTextStyle().getHaloFill() != null) {
|
||||
configureHalo();
|
||||
for (int i = 0; i < numGlyphs; i++) {
|
||||
this.graphics.setTransform(transforms[i]);
|
||||
this.graphics.draw(outlines[i]);
|
||||
}
|
||||
}
|
||||
configureLabelStyle();
|
||||
for (int i = 0; i < numGlyphs; i++) {
|
||||
this.graphics.setTransform(transforms[i]);
|
||||
this.graphics.fill(outlines[i]);
|
||||
}
|
||||
} finally {
|
||||
this.graphics.setTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
|
||||
public double getLinePlacementYAnchor()
|
||||
{
|
||||
TextStyle2D textStyle = getLabel().getTextStyle();
|
||||
LineMetrics lm = textStyle.getFont().getLineMetrics(textStyle.getLabel(),
|
||||
this.graphics.getFontRenderContext());
|
||||
|
||||
if (lm.getHeight() > 0.0F) {
|
||||
return (Math.abs(lm.getStrikethroughOffset()) + lm.getDescent() + lm.getLeading()) /
|
||||
lm.getHeight();
|
||||
}
|
||||
return 0.0D;
|
||||
}
|
||||
|
||||
boolean isLabelUpwards(LineStringCursor cursor)
|
||||
{
|
||||
double labelAngle = cursor.getCurrentAngle() + 1.570796326794897D;
|
||||
|
||||
labelAngle %= 6.283185307179586D;
|
||||
return (labelAngle >= 0.0D) && (labelAngle < 3.141592653589793D);
|
||||
}
|
||||
|
||||
private static class LineInfo
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
String text;
|
||||
GlyphVector gv;
|
||||
TextLayout layout;
|
||||
|
||||
public LineInfo(String text, GlyphVector gv, TextLayout layout)
|
||||
{
|
||||
this.text = text;
|
||||
this.gv = gv;
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public LineInfo(String text, GlyphVector gv)
|
||||
{
|
||||
this.text = text;
|
||||
this.gv = gv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.Date;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public abstract class Layer {
|
||||
private final LayerFactory.LayerType layerType;
|
||||
private String mapName;
|
||||
private String layerName;
|
||||
private String serverName;
|
||||
private CoordinateReferenceSystem layerCRS;
|
||||
private Boolean layerUseCache;
|
||||
private Date layerLastUpdate;
|
||||
private String layerTitle;
|
||||
private String layerAbstract;
|
||||
private String autorID;
|
||||
private String sourceType;
|
||||
private String hashTag;
|
||||
private String sourcPath;
|
||||
|
||||
protected Layer(AVList params) throws Exception {
|
||||
this.layerType = (LayerFactory.LayerType)params.getValue("conf.service.layer.type");
|
||||
if (this.layerType == null) {
|
||||
throw new IllegalArgumentException("LayerType is NULL.");
|
||||
}
|
||||
String sVal = params.getStringValue("conf.service.map.name");
|
||||
if (ServerUtil.isNullString((String)sVal)) {
|
||||
throw new IllegalArgumentException("MapName is NULL.");
|
||||
}
|
||||
this.mapName = sVal.trim().toUpperCase();
|
||||
sVal = params.getStringValue("conf.service.layer.name");
|
||||
if (ServerUtil.isNullString((String)sVal)) {
|
||||
throw new IllegalArgumentException("Layer Name is NULL.");
|
||||
}
|
||||
this.layerName = sVal.trim().toUpperCase();
|
||||
sVal = params.getStringValue("conf.service.ref.server");
|
||||
if (ServerUtil.isNullString((String)sVal)) {
|
||||
throw new IllegalArgumentException("Server Name is NULL.");
|
||||
}
|
||||
this.serverName = sVal.trim();
|
||||
try {
|
||||
CoordinateReferenceSystem crs = (CoordinateReferenceSystem)params.getValue("conf.service.ref.crs");
|
||||
if (crs == null) {
|
||||
Integer srid = params.getIntegerValue("conf.service.ref.srid");
|
||||
crs = CRSMngr.getLayerCRS((int)srid, (boolean)true);
|
||||
}
|
||||
this.layerCRS = crs;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("SRID value is not available.");
|
||||
}
|
||||
Boolean bVal = params.getBooleanValue("conf.service.use.cache");
|
||||
this.layerUseCache = bVal == null ? Boolean.valueOf(false) : bVal;
|
||||
Date dateVal = params.getDateValue("conf.service.last.update");
|
||||
this.layerLastUpdate = dateVal == null ? new Date() : dateVal;
|
||||
this.layerTitle = "O2Map Web Layer : " + this.layerName;
|
||||
sVal = params.getStringValue("conf.service.description");
|
||||
this.layerAbstract = ServerUtil.isNullString((String)sVal) ? "This Layer served FEATURE or IMAGE or COVERAGE on O2Map Web." : sVal.trim();
|
||||
sVal = params.getStringValue("conf.service.o2wps.source.path");
|
||||
this.sourcPath = ServerUtil.isNullString((String)sVal) ? "" : sVal.trim();
|
||||
sVal = params.getStringValue("conf.service.o2wps.hashtag");
|
||||
this.hashTag = ServerUtil.isNullString((String)sVal) ? "" : sVal.trim();
|
||||
sVal = params.getStringValue("conf.service.o2wps.author.id");
|
||||
this.autorID = ServerUtil.isNullString((String)sVal) ? "Anonymous" : sVal.trim();
|
||||
sVal = params.getStringValue("conf.service.o2wps.source.type");
|
||||
if (ServerUtil.isNullString((String)sVal)) {
|
||||
this.sourceType = "shp";
|
||||
} else {
|
||||
this.autorID = sVal.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public LayerFactory.LayerType getLayerType() {
|
||||
return this.layerType;
|
||||
}
|
||||
|
||||
public String getMapName() {
|
||||
return this.mapName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.layerName;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return this.serverName;
|
||||
}
|
||||
|
||||
public abstract String getSourceName();
|
||||
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
return this.layerCRS;
|
||||
}
|
||||
|
||||
public Boolean isUseCache() {
|
||||
return this.layerUseCache;
|
||||
}
|
||||
|
||||
public String getAuthorId() {
|
||||
return this.autorID;
|
||||
}
|
||||
|
||||
public String getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
public Date getLastUpdate() {
|
||||
return this.layerLastUpdate;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.layerTitle;
|
||||
}
|
||||
|
||||
public String getAbstract() {
|
||||
return this.layerAbstract;
|
||||
}
|
||||
|
||||
public String getHashTag() {
|
||||
return this.hashTag;
|
||||
}
|
||||
|
||||
public String getSourcePath() {
|
||||
return this.sourcPath;
|
||||
}
|
||||
|
||||
public void updateCRS() {
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Update Layer CRS [" + this.layerName + "]");
|
||||
CoordinateReferenceSystem crs = CRSMngr.getCRS((String)CRS.toSRS((CoordinateReferenceSystem)this.layerCRS));
|
||||
if (CRS.equalsIgnoreMetadata((Object)this.layerCRS, (Object)crs)) {
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Layer CRS has no change [" + this.layerName + "]");
|
||||
return;
|
||||
}
|
||||
this.layerCRS = crs;
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for Layer [" + this.layerName + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Fail to update CRS for Layer [" + this.layerName + "] :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ReferencedEnvelope getBBox();
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
|
||||
public class LayerFactory {
|
||||
public enum LayerType {
|
||||
JDBC("VECTOR_JDBC", ".jdbc"),
|
||||
SHAPE("VECTOR_SHAPE", ".shape"),
|
||||
GEOWAVE("VECTOR_GEOWAVE", ".gwave"),
|
||||
GROUP("VECTOR_GROUP", ".group"),
|
||||
O2WPSVEC("VECTOR_O2WPS", ".o2wpsvec"),
|
||||
O2WPSCOV("COVERAGE_O2WPS", ".o2wpscov"),
|
||||
WMS("LINK_WMS", ".wms"),
|
||||
WCS("LINK_WCS", ".wcs"),
|
||||
O2IMG("RASTER_O2IMG", ".o2img"),
|
||||
O2DEM("RASTER_O2DEM", ".o2dem");
|
||||
|
||||
private String type;
|
||||
|
||||
private String pre;
|
||||
|
||||
LayerType(String type, String pre) {
|
||||
this.type = type;
|
||||
this.pre = pre;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.pre;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getType();
|
||||
}
|
||||
}
|
||||
|
||||
public static Layer createLayer(LayerType type, AVList params) throws Exception {
|
||||
switch (type) {
|
||||
case JDBC:
|
||||
params.setValue("conf.service.layer.type", LayerType.JDBC);
|
||||
return (Layer)new FeatureLayer(params);
|
||||
case SHAPE:
|
||||
params.setValue("conf.service.layer.type", LayerType.SHAPE);
|
||||
return (Layer)new FeatureLayer(params);
|
||||
case GEOWAVE:
|
||||
params.setValue("conf.service.layer.type", LayerType.GEOWAVE);
|
||||
return (Layer)new FeatureLayer(params);
|
||||
case O2WPSVEC:
|
||||
params.setValue("conf.service.layer.type", LayerType.O2WPSVEC);
|
||||
return (Layer)new FeatureLayer(params);
|
||||
case O2WPSCOV:
|
||||
params.setValue("conf.service.layer.type", LayerType.O2WPSCOV);
|
||||
return (Layer)new O2DemLayer(params);
|
||||
case GROUP:
|
||||
params.setValue("conf.service.layer.type", LayerType.GROUP);
|
||||
return (Layer)new GroupLayer(params);
|
||||
case WMS:
|
||||
params.setValue("conf.service.layer.type", LayerType.WMS);
|
||||
return (Layer)new WMSLayer(params);
|
||||
case WCS:
|
||||
params.setValue("conf.service.layer.type", LayerType.WCS);
|
||||
return (Layer)new WCSLayer(params);
|
||||
case O2IMG:
|
||||
params.setValue("conf.service.layer.type", LayerType.O2IMG);
|
||||
return (Layer)new O2ImgLayer(params);
|
||||
case O2DEM:
|
||||
params.setValue("conf.service.layer.type", LayerType.O2DEM);
|
||||
return (Layer)new O2DemLayer(params);
|
||||
}
|
||||
throw new IllegalArgumentException("LayerType [" + type + "] is not support.");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LayerSet
|
||||
{
|
||||
private final Map serviceMap;
|
||||
private HashMap<String, Layer> layerStore = new HashMap();
|
||||
|
||||
public LayerSet(Map map) {
|
||||
this.serviceMap = map;
|
||||
}
|
||||
|
||||
public void addLayer(Layer layer, boolean overWrite) throws Exception
|
||||
{
|
||||
if ((layer == null) || (ServerUtil.isNullString(layer.getName()))) {
|
||||
throw new IllegalArgumentException("Layer object or Layer name is NULL.");
|
||||
}
|
||||
|
||||
if ((!overWrite) && (this.layerStore.containsKey(layer.getName()))) {
|
||||
throw new IllegalArgumentException("Layer [" + layer.getName() + "] is already exist.");
|
||||
}
|
||||
|
||||
this.layerStore.put(layer.getName(), layer);
|
||||
}
|
||||
|
||||
public void addLayers(ArrayList<Layer> layers, boolean overWrite)
|
||||
throws Exception
|
||||
{
|
||||
if (layers == null) {
|
||||
throw new IllegalArgumentException("Layers object is NULL.");
|
||||
}
|
||||
|
||||
for (Layer layer : layers)
|
||||
{
|
||||
if ((overWrite) || (!this.layerStore.containsKey(layer.getName())))
|
||||
{
|
||||
this.layerStore.put(layer.getName(), layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExistLayer(String name)
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = name.trim().toUpperCase();
|
||||
|
||||
return this.layerStore.containsKey(name);
|
||||
}
|
||||
|
||||
public Layer getLayer(String name) throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
throw new IllegalArgumentException("Layer Name [" + name + "] is NULL.");
|
||||
}
|
||||
|
||||
name = name.trim().toUpperCase();
|
||||
|
||||
Layer layer = (Layer)this.layerStore.get(name);
|
||||
if (layer == null) {
|
||||
throw new NullPointerException("Layer [" + name + "] is not exist in ServiceMap [" + this.serviceMap.getName() + "]");
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers()
|
||||
{
|
||||
return new ArrayList(this.layerStore.values());
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers(LayerFactory.LayerType type)
|
||||
{
|
||||
ArrayList layers = new ArrayList();
|
||||
|
||||
for (Layer layer : this.layerStore.values())
|
||||
{
|
||||
if (layer.getLayerType() == type) {
|
||||
layers.add(layer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
public void removeLayers() {
|
||||
this.layerStore.clear();
|
||||
}
|
||||
|
||||
public Layer removeLayer(String name)
|
||||
throws Exception
|
||||
{
|
||||
Layer layer = getLayer(name);
|
||||
|
||||
this.layerStore.remove(layer.getName());
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
||||
throws Exception
|
||||
{
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName)
|
||||
throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(serverName)) {
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
}
|
||||
serverName = serverName.trim();
|
||||
|
||||
ArrayList resultList = new ArrayList();
|
||||
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName, String sourceName) throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(serverName)) {
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
}
|
||||
serverName = serverName.trim();
|
||||
|
||||
if (ServerUtil.isNullString(sourceName)) {
|
||||
throw new IllegalArgumentException("Source Name [" + sourceName + "] is NULL.");
|
||||
}
|
||||
sourceName = sourceName.trim();
|
||||
|
||||
ArrayList<Layer> resultList = new ArrayList();
|
||||
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
||||
(layer.getSourceName().equalsIgnoreCase(sourceName))) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,667 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.LinearRing;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RectangularShape;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.Parameter;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.factory.CommonFactoryFinder;
|
||||
import org.geotools.feature.SchemaException;
|
||||
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||
import org.geotools.feature.type.GeometryDescriptorImpl;
|
||||
import org.geotools.feature.type.GeometryTypeImpl;
|
||||
import org.geotools.geometry.jts.LiteShape2;
|
||||
import org.geotools.process.Processors;
|
||||
import org.geotools.process.function.ProcessFunction;
|
||||
import org.geotools.renderer.lite.RendererUtilities;
|
||||
import org.geotools.renderer.lite.StyledShapePainter;
|
||||
import org.geotools.renderer.style.SLDStyleFactory;
|
||||
import org.geotools.renderer.style.Style2D;
|
||||
import org.geotools.styling.Description;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.LineSymbolizer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
import org.geotools.styling.RasterSymbolizer;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
import org.geotools.styling.visitor.DpiRescaleStyleVisitor;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.geotools.styling.visitor.UomRescaleStyleVisitor;
|
||||
import org.geotools.util.NumberRange;
|
||||
import org.geotools.util.Range;
|
||||
import org.opengis.feature.Feature;
|
||||
import org.opengis.feature.IllegalAttributeException;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.FeatureType;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.feature.type.GeometryType;
|
||||
import org.opengis.feature.type.Name;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.Literal;
|
||||
import org.opengis.style.GraphicLegend;
|
||||
import org.opengis.util.InternationalString;
|
||||
|
||||
public class LegendGraphicBuilder {
|
||||
public static final double TOLERANCE = 1.0E-6;
|
||||
private static final StyledShapePainter shapePainter = new StyledShapePainter();
|
||||
private static final GeometryFactory geomFac = new GeometryFactory();
|
||||
private LiteShape2 sampleRect;
|
||||
private LiteShape2 sampleLine;
|
||||
private LiteShape2 samplePoint;
|
||||
private final double MINIMUM_SYMBOL_SIZE = 3.0;
|
||||
private final int DEFAULT_WIDTH = 32;
|
||||
private final int DEFAULT_HEIGHT = 32;
|
||||
private final double DEFAULT_SCALE = -1.0;
|
||||
private final AVList parameters;
|
||||
private final HashMap<String, String> legendOption;
|
||||
|
||||
public LegendGraphicBuilder(AVList params) {
|
||||
this.parameters = params;
|
||||
this.legendOption = new HashMap();
|
||||
String optionStr = this.parameters.getStringValue("legend.graphic.option");
|
||||
if (optionStr != null) {
|
||||
String[] options;
|
||||
optionStr = optionStr.toUpperCase();
|
||||
String[] stringArray = options = optionStr.split(";");
|
||||
int n = options.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
String kvStr = stringArray[n2];
|
||||
String[] kv = kvStr.trim().split(":");
|
||||
if (kv.length >= 2) {
|
||||
this.legendOption.put(kv[0].trim().toUpperCase(), kv[1].trim().toUpperCase());
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage buildLegendGraphic() throws Exception {
|
||||
RenderedImage titleImage;
|
||||
String forceTitlesOpt;
|
||||
String forceLabelsOpt;
|
||||
Iterator<FeatureLayer> styleIter;
|
||||
String layerName = this.parameters.getStringValue("legend.graphic.layer");
|
||||
String styleName = this.parameters.getStringValue("legend.graphic.style");
|
||||
String ruleName = this.parameters.getStringValue("legend.graphic.rule");
|
||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)this.parameters.getValue("legend.graphic.sld");
|
||||
if (ServerUtil.isNullString((String)layerName)) {
|
||||
throw new IllegalArgumentException("Layer parameter [" + layerName + "] is not available.");
|
||||
}
|
||||
ArrayList<FeatureType> layers = new ArrayList<FeatureType>();
|
||||
ArrayList<Style> styles = new ArrayList<Style>();
|
||||
Layer serviceLayer = ServerContext.getMap().getLayer(layerName);
|
||||
if (serviceLayer instanceof FeatureLayer) {
|
||||
FeatureLayer fLayer = (FeatureLayer)serviceLayer;
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)fLayer.getLayerType(), (String)fLayer.getServerName(), (String)fLayer.getSourceName());
|
||||
layers.add(featureSource.getSchema());
|
||||
Style style = this.getRenderedStyle(fLayer, styleName, sld);
|
||||
styles.add(style);
|
||||
} else if (serviceLayer instanceof GroupLayer) {
|
||||
GroupLayer gLayer = (GroupLayer)serviceLayer;
|
||||
styleIter = gLayer.getLayerList().iterator();
|
||||
while (styleIter.hasNext()) {
|
||||
FeatureLayer gfLayer;
|
||||
FeatureLayer fLayer = gfLayer = styleIter.next();
|
||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)fLayer.getLayerType(), (String)fLayer.getServerName(), (String)fLayer.getSourceName());
|
||||
layers.add(featureSource.getSchema());
|
||||
Style style2 = this.getRenderedStyle(fLayer, styleName, sld);
|
||||
styles.add(style2);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Request Layer is not Feature Layer or Group Layer.");
|
||||
}
|
||||
Integer width = this.parameters.getIntegerValue("legend.graphic.width", Integer.valueOf(32));
|
||||
Integer height = this.parameters.getIntegerValue("legend.graphic.height", Integer.valueOf(32));
|
||||
Double dpi = null;
|
||||
Double scaleFactor = null;
|
||||
try {
|
||||
dpi = Double.parseDouble(this.legendOption.get("DPI"));
|
||||
double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
|
||||
if (dpi != standardDpi) {
|
||||
scaleFactor = dpi / standardDpi;
|
||||
width = (int)Math.round((double)width.intValue() * scaleFactor);
|
||||
height = (int)Math.round((double)height.intValue() * scaleFactor);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
width = this.parameters.getIntegerValue("legend.graphic.width", Integer.valueOf(32));
|
||||
height = this.parameters.getIntegerValue("legend.graphic.height", Integer.valueOf(32));
|
||||
dpi = null;
|
||||
scaleFactor = null;
|
||||
}
|
||||
Double scale = this.parameters.getDoubleValue("legend.graphic.scale", Double.valueOf(-1.0));
|
||||
Double pixelsPerMeters = null;
|
||||
try {
|
||||
if (scale > 0.0) {
|
||||
Map dpiMap = Collections.EMPTY_MAP;
|
||||
if (dpi != null) {
|
||||
dpiMap.put("dpi", dpi);
|
||||
}
|
||||
pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio((double)scale, (Map)dpiMap);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
pixelsPerMeters = null;
|
||||
}
|
||||
String format = this.parameters.getStringValue("legend.graphic.format", "image/png");
|
||||
boolean transparent = false;
|
||||
if (format.split("/")[1].equalsIgnoreCase("PNG")) {
|
||||
transparent = true;
|
||||
}
|
||||
boolean forceLabelsOn = false;
|
||||
if (this.legendOption.get("FORCELABELS") instanceof String && ((forceLabelsOpt = this.legendOption.get("FORCELABELS")).equalsIgnoreCase("ON") || forceLabelsOpt.equalsIgnoreCase("YES") || forceLabelsOpt.equalsIgnoreCase("TRUE") || forceLabelsOpt.equalsIgnoreCase("1"))) {
|
||||
forceLabelsOn = true;
|
||||
}
|
||||
boolean forceTitlesOn = false;
|
||||
if (this.legendOption.get("FORCETITLES") instanceof String && ((forceTitlesOpt = this.legendOption.get("FORCETITLES")).equalsIgnoreCase("ON") || forceTitlesOpt.equalsIgnoreCase("YES") || forceTitlesOpt.equalsIgnoreCase("TRUE") || forceTitlesOpt.equalsIgnoreCase("1"))) {
|
||||
forceTitlesOn = true;
|
||||
}
|
||||
double minimumSymbolSize = 3.0;
|
||||
try {
|
||||
String minSymbolSizeOpt = this.legendOption.get("MINSYMBOLSIZE");
|
||||
minimumSymbolSize = Double.parseDouble(minSymbolSizeOpt);
|
||||
}
|
||||
catch (Exception minSymbolSizeOpt) {
|
||||
// empty catch block
|
||||
}
|
||||
ArrayList<RenderedImage> layersImages = new ArrayList<RenderedImage>();
|
||||
if (forceTitlesOn && (titleImage = this.getLayerTitle(serviceLayer.getName(), width, height, transparent)) != null) {
|
||||
layersImages.add(titleImage);
|
||||
}
|
||||
int pos = 0;
|
||||
while (pos < layers.size()) {
|
||||
Rule[] applicableRules;
|
||||
FeatureType renderLayer = (FeatureType)layers.get(pos);
|
||||
Style renderStyle = (Style)styles.get(pos);
|
||||
if (scaleFactor != null) {
|
||||
DpiRescaleStyleVisitor dpiVisitor = new DpiRescaleStyleVisitor(scaleFactor.doubleValue());
|
||||
dpiVisitor.visit(renderStyle);
|
||||
renderStyle = (Style)dpiVisitor.getCopy();
|
||||
}
|
||||
if (pixelsPerMeters != null) {
|
||||
UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters.doubleValue());
|
||||
rescaleVisitor.visit(renderStyle);
|
||||
renderStyle = (Style)rescaleVisitor.getCopy();
|
||||
}
|
||||
boolean hasVectorTransformation = false;
|
||||
boolean hasRasterTransformation = false;
|
||||
List ftsList = renderStyle.featureTypeStyles();
|
||||
int i = 0;
|
||||
while (i < ftsList.size()) {
|
||||
ProcessFunction processFunction;
|
||||
Name processName;
|
||||
Map outputs;
|
||||
FeatureTypeStyle fts = (FeatureTypeStyle)ftsList.get(i);
|
||||
Expression exp = fts.getTransformation();
|
||||
if (exp != null && !(outputs = Processors.getResultInfo((Name)(processName = (processFunction = (ProcessFunction)exp).getProcessName()), null)).isEmpty()) {
|
||||
Parameter output = (Parameter)outputs.values().iterator().next();
|
||||
if (SimpleFeatureCollection.class.isAssignableFrom(output.getType())) {
|
||||
hasVectorTransformation = true;
|
||||
break;
|
||||
}
|
||||
if (GridCoverage2D.class.isAssignableFrom(output.getType())) {
|
||||
hasRasterTransformation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
Object sampleFeature = hasVectorTransformation ? this.createSampleFeature() : this.createSampleFeature(renderLayer);
|
||||
FeatureTypeStyle[] ftStyles = renderStyle.featureTypeStyles().toArray(new FeatureTypeStyle[0]);
|
||||
if (ruleName != null) {
|
||||
Rule rule = LegendUtils.getRule((FeatureTypeStyle[])ftStyles, (String)ruleName.trim());
|
||||
if (rule == null) {
|
||||
throw new RuntimeException("Specified style does not contains a rule named " + ruleName);
|
||||
}
|
||||
applicableRules = new Rule[]{rule};
|
||||
} else {
|
||||
applicableRules = LegendUtils.getApplicableRules((FeatureTypeStyle[])ftStyles, (double)scale);
|
||||
}
|
||||
SLDStyleFactory styleFactory = new SLDStyleFactory();
|
||||
NumberRange scaleRange = NumberRange.create((double)scale, (double)scale);
|
||||
double symbolScale = this.calcSymbolScale(width, height, renderLayer, (Feature)sampleFeature, applicableRules, minimumSymbolSize);
|
||||
ArrayList<RenderedImage> legendsStack = new ArrayList<RenderedImage>(applicableRules.length);
|
||||
int i2 = 0;
|
||||
while (i2 < applicableRules.length) {
|
||||
BufferedImage image = this.createImage(width, height, transparent);
|
||||
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||
Graphics2D graphics = this.prepareTransparency(transparent, backgroundColor, image);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
Feature sample = this.getSampleFeatureForRule(renderLayer, (Feature)sampleFeature, applicableRules[i2]);
|
||||
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
|
||||
Symbolizer[] symbolizers = applicableRules[i2].getSymbolizers();
|
||||
GraphicLegend legend = applicableRules[i2].getLegend();
|
||||
if (legend != null) {
|
||||
if (this.samplePoint == null) {
|
||||
Coordinate coord = new Coordinate((double)(width / 2), (double)(height / 2));
|
||||
try {
|
||||
this.samplePoint = new LiteShape2((Geometry)geomFac.createPoint(coord), null, null, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.samplePoint = null;
|
||||
}
|
||||
}
|
||||
shapePainter.paint(graphics, this.samplePoint, legend, scale.doubleValue(), false);
|
||||
} else {
|
||||
int sIdx = 0;
|
||||
while (sIdx < symbolizers.length) {
|
||||
PointSymbolizer pointSymbolizer;
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (symbolizer instanceof RasterSymbolizer) {
|
||||
throw new IllegalStateException("It is not legal to have a RasterSymbolizer here");
|
||||
}
|
||||
if (symbolScale > 1.0 && symbolizer instanceof PointSymbolizer && (pointSymbolizer = this.cloneSymbolizer(symbolizer)).getGraphic() != null) {
|
||||
double size = this.getPointSymbolizerSize(sample, pointSymbolizer, Math.min(width, height) - 4);
|
||||
pointSymbolizer.getGraphic().setSize((Expression)ff.literal(size / symbolScale + minimumSymbolSize));
|
||||
symbolizer = pointSymbolizer;
|
||||
}
|
||||
Style2D style2d = styleFactory.createStyle((Object)sample, symbolizer, (Range)scaleRange);
|
||||
LiteShape2 shape = this.getSampleShape(symbolizer, width, height);
|
||||
if (style2d != null) {
|
||||
shapePainter.paint(graphics, shape, style2d, scale.doubleValue());
|
||||
}
|
||||
++sIdx;
|
||||
}
|
||||
}
|
||||
legendsStack.add(image);
|
||||
graphics.dispose();
|
||||
++i2;
|
||||
}
|
||||
BufferedImage image = this.mergeLegends(legendsStack, applicableRules, forceLabelsOn, transparent);
|
||||
if (image != null) {
|
||||
layersImages.add(image);
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
BufferedImage finalLegend = this.mergeLegends(layersImages, null, forceLabelsOn, transparent);
|
||||
if (finalLegend == null) {
|
||||
throw new IllegalArgumentException("no legend passed");
|
||||
}
|
||||
return finalLegend;
|
||||
}
|
||||
|
||||
private Style getRenderedStyle(FeatureLayer layer, String styleName, StyledLayerDescriptor sld) {
|
||||
Style style2;
|
||||
ArrayList<Style> styleList = ServerUtil.isNullString((String)styleName) ? StyleMngr.getStylesFromSLD((String)layer.getName(), (StyledLayerDescriptor)sld) : StyleMngr.getStylesFromSLD((String)layer.getName(), (String)styleName, (StyledLayerDescriptor)sld);
|
||||
if (styleList.size() == 0) {
|
||||
return layer.getRenderStyle(styleName);
|
||||
}
|
||||
for (Style style1 : styleList) {
|
||||
if (!style1.isDefault()) continue;
|
||||
if (style1 instanceof NamedStyle) {
|
||||
return layer.getRenderStyle(style1.getName());
|
||||
}
|
||||
return style1;
|
||||
}
|
||||
style2 = (Style)styleList.get(0);
|
||||
if (style2 instanceof NamedStyle) {
|
||||
return layer.getRenderStyle(style2.getName());
|
||||
}
|
||||
return style2;
|
||||
}
|
||||
|
||||
private BufferedImage createImage(int w, int h, boolean transparent) {
|
||||
if (transparent) {
|
||||
return new BufferedImage(w, h, 6);
|
||||
}
|
||||
return new BufferedImage(w, h, 5);
|
||||
}
|
||||
|
||||
private Graphics2D prepareTransparency(boolean transparent, Color bgColor, BufferedImage preparedImage) {
|
||||
Graphics2D graphic = preparedImage.createGraphics();
|
||||
HashMap<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
|
||||
hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
graphic.setRenderingHints(hintsMap);
|
||||
if (transparent) {
|
||||
int type = 2;
|
||||
graphic.setComposite(AlphaComposite.getInstance(type));
|
||||
Color c = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 0);
|
||||
graphic.setBackground(bgColor);
|
||||
graphic.setColor(c);
|
||||
graphic.fillRect(0, 0, preparedImage.getWidth(), preparedImage.getHeight());
|
||||
type = 3;
|
||||
graphic.setComposite(AlphaComposite.getInstance(type));
|
||||
} else {
|
||||
graphic.setColor(bgColor);
|
||||
graphic.fillRect(0, 0, preparedImage.getWidth(), preparedImage.getHeight());
|
||||
}
|
||||
return graphic;
|
||||
}
|
||||
|
||||
private RenderedImage getLayerTitle(String title, int w, int h, boolean transparent) {
|
||||
if (title == null) {
|
||||
title = "Legend";
|
||||
}
|
||||
BufferedImage image = this.createImage(w, h, transparent);
|
||||
return this.getRenderedLabel(image, title);
|
||||
}
|
||||
|
||||
private BufferedImage getRenderedLabel(BufferedImage image, String label) {
|
||||
Font labelFont = LegendUtils.getLabelFont(this.legendOption);
|
||||
boolean useAA = LegendUtils.isFontAntiAliasing(this.legendOption);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setFont(labelFont);
|
||||
if (useAA) {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
} else {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
}
|
||||
return LegendUtils.renderLabel((String)label, (Graphics2D)graphics, this.legendOption);
|
||||
}
|
||||
|
||||
private SimpleFeature createSampleFeature() {
|
||||
SimpleFeatureType type;
|
||||
try {
|
||||
type = DataUtilities.createType((String)"Sample", (String)"the_geom:Geometry");
|
||||
}
|
||||
catch (SchemaException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return SimpleFeatureBuilder.template((SimpleFeatureType)type, null);
|
||||
}
|
||||
|
||||
private Feature createSampleFeature(FeatureType schema) {
|
||||
Feature sampleFeature;
|
||||
try {
|
||||
sampleFeature = schema instanceof SimpleFeatureType ? (this.hasMixedGeometry((SimpleFeatureType)schema) ? null : SimpleFeatureBuilder.template((SimpleFeatureType)((SimpleFeatureType)schema), null)) : DataUtilities.templateFeature((FeatureType)schema);
|
||||
}
|
||||
catch (IllegalAttributeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return sampleFeature;
|
||||
}
|
||||
|
||||
private boolean hasMixedGeometry(SimpleFeatureType schema) {
|
||||
for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) {
|
||||
if (!this.isMixedGeometry(attDesc)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMixedGeometry(AttributeDescriptor attDesc) {
|
||||
return attDesc instanceof GeometryDescriptor && attDesc.getType().getBinding() == Geometry.class;
|
||||
}
|
||||
|
||||
private double calcSymbolScale(int width, int height, FeatureType featureType, Feature feature, Rule[] rules, double minimumSymbolsSize) {
|
||||
double minSize = Double.MAX_VALUE;
|
||||
double maxSize = 0.0;
|
||||
int ruleCount = rules.length;
|
||||
int i = 0;
|
||||
while (i < ruleCount) {
|
||||
Feature sample = this.getSampleFeatureForRule(featureType, feature, rules[i]);
|
||||
Symbolizer[] symbolizers = rules[i].getSymbolizers();
|
||||
int sIdx = 0;
|
||||
while (sIdx < symbolizers.length) {
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (symbolizer instanceof PointSymbolizer) {
|
||||
double size = this.getPointSymbolizerSize(sample, (PointSymbolizer)symbolizer, Math.min(width, height));
|
||||
if (size < minSize) {
|
||||
minSize = size;
|
||||
}
|
||||
if (size > maxSize) {
|
||||
maxSize = size;
|
||||
}
|
||||
}
|
||||
++sIdx;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (minSize != maxSize) {
|
||||
return (maxSize - minSize + 1.0) / ((double)Math.min(width, height) - minimumSymbolsSize);
|
||||
}
|
||||
return maxSize / ((double)Math.min(width, height) - minimumSymbolsSize);
|
||||
}
|
||||
|
||||
private Feature getSampleFeatureForRule(FeatureType featureType, Feature sample, Rule rule) {
|
||||
Symbolizer[] symbolizers = rule.getSymbolizers();
|
||||
if (sample == null) {
|
||||
int dimensionality = 1;
|
||||
int sIdx = 0;
|
||||
while (sIdx < symbolizers.length) {
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
|
||||
dimensionality = 2;
|
||||
}
|
||||
if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
|
||||
dimensionality = 3;
|
||||
}
|
||||
++sIdx;
|
||||
}
|
||||
return this.createSampleFeature(featureType, dimensionality);
|
||||
}
|
||||
return sample;
|
||||
}
|
||||
|
||||
private Feature createSampleFeature(FeatureType schema, int dimensionality) {
|
||||
if (schema instanceof SimpleFeatureType) {
|
||||
schema = this.cloneWithDimensionality(schema, dimensionality);
|
||||
}
|
||||
return this.createSampleFeature(schema);
|
||||
}
|
||||
|
||||
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
|
||||
SimpleFeatureType simpleFt = (SimpleFeatureType)schema;
|
||||
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
|
||||
builder.setName(schema.getName());
|
||||
builder.setCRS(schema.getCoordinateReferenceSystem());
|
||||
for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
|
||||
if (this.isMixedGeometry(desc)) {
|
||||
GeometryDescriptor geomDescriptor = (GeometryDescriptor)desc;
|
||||
GeometryType geomType = geomDescriptor.getType();
|
||||
Class<?> geometryClass = this.getGeometryForDimensionality(dimensionality);
|
||||
GeometryTypeImpl gt = new GeometryTypeImpl(geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription());
|
||||
builder.add((AttributeDescriptor)new GeometryDescriptorImpl((GeometryType)gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue()));
|
||||
continue;
|
||||
}
|
||||
builder.add(desc);
|
||||
}
|
||||
schema = builder.buildFeatureType();
|
||||
return schema;
|
||||
}
|
||||
|
||||
private Class<?> getGeometryForDimensionality(int dimensionality) {
|
||||
if (dimensionality == 1) {
|
||||
return Point.class;
|
||||
}
|
||||
if (dimensionality == 2) {
|
||||
return LineString.class;
|
||||
}
|
||||
return Polygon.class;
|
||||
}
|
||||
|
||||
private double getPointSymbolizerSize(Feature feature, PointSymbolizer pointSymbolizer, int defaultSize) {
|
||||
Object size;
|
||||
Expression sizeExp;
|
||||
if (pointSymbolizer.getGraphic() != null && (sizeExp = pointSymbolizer.getGraphic().getSize()) instanceof Literal && (size = sizeExp.evaluate((Object)feature)) != null) {
|
||||
if (size instanceof Double) {
|
||||
return (Double)size;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(size.toString());
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return defaultSize;
|
||||
}
|
||||
}
|
||||
return defaultSize;
|
||||
}
|
||||
|
||||
private PointSymbolizer cloneSymbolizer(Symbolizer symbolizer) {
|
||||
DuplicatingStyleVisitor duplicator = new DuplicatingStyleVisitor();
|
||||
symbolizer.accept((StyleVisitor)duplicator);
|
||||
PointSymbolizer pointSymbolizer = (PointSymbolizer)duplicator.getCopy();
|
||||
return pointSymbolizer;
|
||||
}
|
||||
|
||||
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
|
||||
LiteShape2 sampleShape;
|
||||
float hpad = (float)legendWidth * 0.15f;
|
||||
float vpad = (float)legendHeight * 0.15f;
|
||||
if (symbolizer instanceof LineSymbolizer) {
|
||||
if (this.sampleLine == null) {
|
||||
Coordinate[] coords = new Coordinate[]{new Coordinate((double)hpad, (double)((float)legendHeight - vpad - 1.0f)), new Coordinate((double)((float)legendWidth - hpad - 1.0f), (double)vpad)};
|
||||
LineString geom = geomFac.createLineString(coords);
|
||||
try {
|
||||
this.sampleLine = new LiteShape2((Geometry)geom, null, null, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.sampleLine = null;
|
||||
}
|
||||
}
|
||||
sampleShape = this.sampleLine;
|
||||
} else if (symbolizer instanceof PolygonSymbolizer || symbolizer instanceof RasterSymbolizer) {
|
||||
if (this.sampleRect == null) {
|
||||
float w = (float)legendWidth - 2.0f * hpad - 1.0f;
|
||||
float h = (float)legendHeight - 2.0f * vpad - 1.0f;
|
||||
Coordinate[] coords = new Coordinate[]{new Coordinate((double)hpad, (double)vpad), new Coordinate((double)hpad, (double)(vpad + h)), new Coordinate((double)(hpad + w), (double)(vpad + h)), new Coordinate((double)(hpad + w), (double)vpad), new Coordinate((double)hpad, (double)vpad)};
|
||||
LinearRing shell = geomFac.createLinearRing(coords);
|
||||
Polygon geom = geomFac.createPolygon(shell, null);
|
||||
try {
|
||||
this.sampleRect = new LiteShape2((Geometry)geom, null, null, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.sampleRect = null;
|
||||
}
|
||||
}
|
||||
sampleShape = this.sampleRect;
|
||||
} else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
|
||||
if (this.samplePoint == null) {
|
||||
Coordinate coord = new Coordinate((double)(legendWidth / 2), (double)(legendHeight / 2));
|
||||
try {
|
||||
this.samplePoint = new LiteShape2((Geometry)geomFac.createPoint(coord), null, null, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.samplePoint = null;
|
||||
}
|
||||
}
|
||||
sampleShape = this.samplePoint;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
|
||||
}
|
||||
return sampleShape;
|
||||
}
|
||||
|
||||
private BufferedImage mergeLegends(List<RenderedImage> imageStack, Rule[] rules, boolean forceLabelsOn, boolean transparent) {
|
||||
BufferedImage finalLegend;
|
||||
Font labelFont = LegendUtils.getLabelFont(this.legendOption);
|
||||
boolean useAA = LegendUtils.isFontAntiAliasing(this.legendOption);
|
||||
if (imageStack.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (!(imageStack.size() != 1 || forceLabelsOn && rules != null)) {
|
||||
finalLegend = (BufferedImage)imageStack.get(0);
|
||||
} else {
|
||||
int imgCount = imageStack.size();
|
||||
String[] labels = new String[imgCount];
|
||||
BufferedImage img = (BufferedImage)imageStack.get(0);
|
||||
int totalHeight = 0;
|
||||
int totalWidth = 0;
|
||||
int[] rowHeights = new int[imgCount];
|
||||
BufferedImage[] labelsGraphics = new BufferedImage[imgCount];
|
||||
int i = 0;
|
||||
while (i < imgCount) {
|
||||
img = (BufferedImage)imageStack.get(i);
|
||||
if (!forceLabelsOn || rules == null) {
|
||||
totalWidth = (int)Math.ceil(Math.max(img.getWidth(), totalWidth));
|
||||
rowHeights[i] = img.getHeight();
|
||||
totalHeight += img.getHeight();
|
||||
} else {
|
||||
InternationalString title;
|
||||
Rule rule = rules[i];
|
||||
Description description = rule.getDescription();
|
||||
if (description != null && description.getTitle() != null && !ServerUtil.isNullString((String)(title = description.getTitle()).toString())) {
|
||||
labels[i] = title.toString();
|
||||
}
|
||||
if (ServerUtil.isNullString((String)labels[i])) {
|
||||
labels[i] = ServerUtil.isNullString((String)rule.getName()) ? "RULE " + i : rule.getName();
|
||||
}
|
||||
if (labels[i] != null && labels[i].length() > 0) {
|
||||
BufferedImage renderedLabel;
|
||||
labelsGraphics[i] = renderedLabel = this.getRenderedLabel(img, labels[i]);
|
||||
Rectangle2D.Double bounds = new Rectangle2D.Double(0.0, 0.0, renderedLabel.getWidth(), renderedLabel.getHeight());
|
||||
totalWidth = (int)Math.ceil(Math.max((double)img.getWidth() + ((RectangularShape)bounds).getWidth(), (double)totalWidth));
|
||||
rowHeights[i] = (int)Math.ceil(Math.max((double)img.getHeight(), ((RectangularShape)bounds).getHeight()));
|
||||
} else {
|
||||
totalWidth = (int)Math.ceil(Math.max(img.getWidth(), totalWidth));
|
||||
rowHeights[i] = (int)Math.ceil(img.getHeight());
|
||||
labelsGraphics[i] = null;
|
||||
}
|
||||
totalHeight += rowHeights[i];
|
||||
}
|
||||
++i;
|
||||
}
|
||||
finalLegend = this.createImage(totalWidth += 2, totalHeight, transparent);
|
||||
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||
Graphics2D finalGraphics = this.prepareTransparency(transparent, backgroundColor, finalLegend);
|
||||
int topOfRow = 0;
|
||||
int i2 = 0;
|
||||
while (i2 < imgCount) {
|
||||
img = (BufferedImage)imageStack.get(i2);
|
||||
int y = topOfRow;
|
||||
if (img.getHeight() < rowHeights[i2]) {
|
||||
y += (int)((double)(rowHeights[i2] - img.getHeight()) / 2.0);
|
||||
}
|
||||
finalGraphics.drawImage((Image)img, 0, y, null);
|
||||
if (!forceLabelsOn || rules == null) {
|
||||
topOfRow += rowHeights[i2];
|
||||
} else {
|
||||
finalGraphics.setFont(labelFont);
|
||||
if (useAA) {
|
||||
finalGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
} else {
|
||||
finalGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
}
|
||||
if (labels[i2] != null && labels[i2].length() > 0) {
|
||||
BufferedImage renderedLabel = labelsGraphics[i2];
|
||||
y = topOfRow;
|
||||
if (renderedLabel.getHeight() < rowHeights[i2]) {
|
||||
y += (int)((double)(rowHeights[i2] - renderedLabel.getHeight()) / 2.0);
|
||||
}
|
||||
finalGraphics.drawImage((Image)renderedLabel, img.getWidth(), y, null);
|
||||
renderedLabel.flush();
|
||||
labelsGraphics[i2] = null;
|
||||
}
|
||||
topOfRow += rowHeights[i2];
|
||||
}
|
||||
++i2;
|
||||
}
|
||||
finalGraphics.dispose();
|
||||
}
|
||||
return finalLegend;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,248 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.Rectangle2D.Double;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import org.geotools.renderer.lite.RendererUtilities;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.Rule;
|
||||
|
||||
public class LegendUtils
|
||||
{
|
||||
public static final String DEFAULT_FONT_NAME = "Sans-Serif";
|
||||
public static final int DEFAULT_FONT_TYPE = 0;
|
||||
public static final int DEFAULT_FONT_SIZE = 12;
|
||||
public static final Font DEFAULT_FONT = new Font("Sans-Serif", 0, 12);
|
||||
|
||||
public static final Color DEFAULT_BG_COLOR = Color.WHITE;
|
||||
|
||||
public static final Color DEFAULT_FONT_COLOR = Color.BLACK;
|
||||
public static final float hpaddingFactor = 0.15F;
|
||||
public static final float vpaddingFactor = 0.15F;
|
||||
|
||||
public static Font getLabelFont(Map legendOptions)
|
||||
{
|
||||
if (legendOptions == null) {
|
||||
return DEFAULT_FONT;
|
||||
}
|
||||
|
||||
String legendFontName = "Sans-Serif";
|
||||
if (legendOptions.get("FONTNAME") != null) {
|
||||
legendFontName = (String)legendOptions.get("FONTNAME");
|
||||
}
|
||||
|
||||
int legendFontFamily = 0;
|
||||
if (legendOptions.get("FONTSTYLE") != null) {
|
||||
String legendFontFamily_ = (String)legendOptions.get("FONTSTYLE");
|
||||
if (legendFontFamily_.equalsIgnoreCase("ITALIC"))
|
||||
legendFontFamily = 2;
|
||||
else if (legendFontFamily_.equalsIgnoreCase("BOLD")) {
|
||||
legendFontFamily = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int legendFontSize = 12;
|
||||
if (legendOptions.get("FONTSIZE") != null) {
|
||||
try {
|
||||
legendFontSize = Integer.valueOf((String)legendOptions.get("FONTSIZE")).intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
legendFontSize = 12;
|
||||
}
|
||||
}
|
||||
|
||||
double dpi = RendererUtilities.getDpi(legendOptions);
|
||||
double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
|
||||
if (dpi != standardDpi) {
|
||||
double scaleFactor = dpi / standardDpi;
|
||||
legendFontSize = (int)Math.ceil(legendFontSize * scaleFactor);
|
||||
}
|
||||
|
||||
if ((legendFontFamily == 0) && (legendFontName.equalsIgnoreCase("Sans-Serif")) && (
|
||||
(legendFontSize == 12) || (legendFontSize <= 0))) {
|
||||
return DEFAULT_FONT;
|
||||
}
|
||||
return new Font(legendFontName, legendFontFamily, legendFontSize);
|
||||
}
|
||||
|
||||
public static boolean isFontAntiAliasing(Map legendOptions)
|
||||
{
|
||||
if ((legendOptions.get("FONTANTIALIASING") instanceof String)) {
|
||||
String aaVal = (String)legendOptions.get("FONTANTIALIASING");
|
||||
if ((aaVal.equalsIgnoreCase("ON")) || (aaVal.equalsIgnoreCase("TRUE")) ||
|
||||
(aaVal.equalsIgnoreCase("YES")) || (aaVal.equalsIgnoreCase("Y")) ||
|
||||
(aaVal.equalsIgnoreCase("1"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static BufferedImage renderLabel(String label, Graphics2D g, Map legendOption)
|
||||
{
|
||||
Color labelColor = getLabelFontColor(legendOption);
|
||||
BufferedImage renderedLabel;
|
||||
if ((label.indexOf("\n") != -1) || (label.indexOf("\\n") != -1))
|
||||
{
|
||||
Rectangle2D bounds = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
|
||||
ArrayList lineHeight = new ArrayList();
|
||||
|
||||
String realLabel = label.replaceAll("\\\\n", "\n");
|
||||
StringTokenizer st = new StringTokenizer(realLabel, "\n\r\f");
|
||||
|
||||
while (st.hasMoreElements()) {
|
||||
String token = st.nextToken();
|
||||
Rectangle2D thisLineBounds = g.getFontMetrics().getStringBounds(token, g);
|
||||
|
||||
int thisLineHeight = (int)Math.ceil(thisLineBounds.getHeight());
|
||||
bounds.add(0.0D, thisLineHeight + bounds.getHeight());
|
||||
bounds.add(thisLineBounds.getWidth(), 0.0D);
|
||||
lineHeight.add(Integer.valueOf((int)Math.ceil(thisLineBounds.getHeight())));
|
||||
}
|
||||
|
||||
renderedLabel = new BufferedImage((int)Math.ceil(bounds.getWidth()),
|
||||
(int)Math.ceil(bounds.getHeight()), 2);
|
||||
|
||||
st = new StringTokenizer(realLabel, "\n\r\f");
|
||||
|
||||
Graphics2D rlg = renderedLabel.createGraphics();
|
||||
rlg.setColor(labelColor);
|
||||
rlg.setFont(g.getFont());
|
||||
rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
|
||||
|
||||
int y = 0 - g.getFontMetrics().getDescent();
|
||||
int c = 0;
|
||||
|
||||
while (st.hasMoreElements()) {
|
||||
y += ((Integer)lineHeight.get(c++)).intValue();
|
||||
rlg.drawString(st.nextToken(), 0, y);
|
||||
}
|
||||
rlg.dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
int height = (int)Math.ceil(g.getFontMetrics().getStringBounds(label, g).getHeight());
|
||||
int width = (int)Math.ceil(g.getFontMetrics().getStringBounds(label, g).getWidth());
|
||||
renderedLabel = new BufferedImage(width, height, 2);
|
||||
|
||||
Graphics2D rlg = renderedLabel.createGraphics();
|
||||
rlg.setColor(labelColor);
|
||||
rlg.setFont(g.getFont());
|
||||
rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
|
||||
rlg.drawString(label, 0, height - rlg.getFontMetrics().getDescent());
|
||||
rlg.dispose();
|
||||
}
|
||||
|
||||
return renderedLabel;
|
||||
}
|
||||
|
||||
public static Color getLabelFontColor(Map legendOptions)
|
||||
{
|
||||
String color = legendOptions != null ? (String)legendOptions.get("FONTCOLOR") : null;
|
||||
if (color == null) {
|
||||
return DEFAULT_FONT_COLOR;
|
||||
}
|
||||
try
|
||||
{
|
||||
return color(color); } catch (NumberFormatException e) {
|
||||
}
|
||||
return DEFAULT_FONT_COLOR;
|
||||
}
|
||||
|
||||
public static Rule getRule(FeatureTypeStyle[] fts, String rule)
|
||||
{
|
||||
Rule sldRule = null;
|
||||
for (int i = 0; i < fts.length; i++) {
|
||||
Rule[] rules = fts[i].getRules();
|
||||
|
||||
for (int r = 0; r < rules.length; r++) {
|
||||
if (rule.equalsIgnoreCase(rules[r].getName())) {
|
||||
sldRule = rules[r];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sldRule;
|
||||
}
|
||||
|
||||
public static Rule[] getApplicableRules(FeatureTypeStyle[] ftStyles, double scaleDenominator)
|
||||
{
|
||||
List ruleList = new ArrayList();
|
||||
|
||||
for (int i = 0; i < ftStyles.length; i++) {
|
||||
FeatureTypeStyle fts = ftStyles[i];
|
||||
Rule[] rules = fts.getRules();
|
||||
|
||||
for (int j = 0; j < rules.length; j++) {
|
||||
Rule r = rules[j];
|
||||
|
||||
if (isWithInScale(r, scaleDenominator)) {
|
||||
ruleList.add(r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (Rule[])ruleList.toArray(new Rule[ruleList.size()]);
|
||||
}
|
||||
|
||||
public static boolean isWithInScale(Rule r, double scaleDenominator)
|
||||
{
|
||||
return (scaleDenominator == -1.0D) || (
|
||||
(r.getMinScaleDenominator() - 1.0E-006D <= scaleDenominator) && (
|
||||
r.getMaxScaleDenominator() + 1.0E-006D > scaleDenominator));
|
||||
}
|
||||
|
||||
public static Color getBackgroundColor(Map legendOptions)
|
||||
{
|
||||
if (legendOptions == null) {
|
||||
return DEFAULT_BG_COLOR;
|
||||
}
|
||||
|
||||
Object clr = legendOptions.get("BGCOLOR");
|
||||
if ((clr instanceof Color))
|
||||
return (Color)clr;
|
||||
if (clr == null) {
|
||||
return DEFAULT_BG_COLOR;
|
||||
}
|
||||
try
|
||||
{
|
||||
return color((String)clr); } catch (NumberFormatException e) {
|
||||
}
|
||||
return DEFAULT_BG_COLOR;
|
||||
}
|
||||
|
||||
public static Color color(String hex)
|
||||
{
|
||||
if (hex.startsWith("0x")) {
|
||||
hex = hex.substring(2);
|
||||
}
|
||||
if (!hex.startsWith("#")) {
|
||||
hex = "#" + hex;
|
||||
}
|
||||
return Color.decode(hex);
|
||||
}
|
||||
|
||||
public static enum HAlign
|
||||
{
|
||||
LEFT, CENTERED, RIGHT, JUSTIFIED;
|
||||
}
|
||||
|
||||
public static enum VAlign
|
||||
{
|
||||
TOP, MIDDLE, BOTTOM;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public abstract class LinkLayer extends Layer
|
||||
{
|
||||
private URL serviceURL;
|
||||
private String serviceLayerNames;
|
||||
|
||||
protected LinkLayer(AVList params)
|
||||
throws Exception
|
||||
{
|
||||
super(params);
|
||||
try
|
||||
{
|
||||
URL urlVal = params.getURLValue("conf.service.ref.server");
|
||||
this.serviceURL = urlVal;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new Exception("Remote Server URL is not available. :: " + e.getMessage());
|
||||
}
|
||||
|
||||
String sVal = params.getStringValue("conf.service.ref.source");
|
||||
if (ServerUtil.isNullString(sVal)) {
|
||||
throw new Exception("Remote Service Layers value is NULL.");
|
||||
}
|
||||
this.serviceLayerNames = sVal.trim();
|
||||
}
|
||||
|
||||
public String getSourceName()
|
||||
{
|
||||
return this.serviceLayerNames;
|
||||
}
|
||||
|
||||
public URL getServiceURL() {
|
||||
return this.serviceURL;
|
||||
}
|
||||
|
||||
public String getServiceLayerNames() {
|
||||
return this.serviceLayerNames;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,219 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class LogCacheManager
|
||||
{
|
||||
private static LogCacheManager instance;
|
||||
private Timer timer;
|
||||
private long timerRepeat;
|
||||
private long cachePeriod;
|
||||
private long folderSize;
|
||||
private File logDir = null;
|
||||
private String type = null;
|
||||
private int value = 0;
|
||||
|
||||
private LogCacheManager() {
|
||||
this.timerRepeat = 60000L;
|
||||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
public static LogCacheManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new LogCacheManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void start(HashMap<String, Object> map)
|
||||
{
|
||||
String dirValue = (String)map.get("conf.xml.log.dir");
|
||||
this.logDir = new File(dirValue.trim());
|
||||
if (!this.logDir.exists()) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Directory is not exist. Now log cache always saved.");
|
||||
return;
|
||||
}if (this.logDir.isFile()) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Directory is not Directory. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = ((String)map.get("conf.xml.log.cache.type"));
|
||||
if ((this.type == null) || (this.type.trim().equals(""))) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Type is NULL. Now log cache always saved.");
|
||||
return;
|
||||
}if ((!this.type.trim().equalsIgnoreCase("SIZE")) && (!this.type.trim().equalsIgnoreCase("DAY"))) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Type is support only SIZE/DAY. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
this.type = this.type.trim().toUpperCase();
|
||||
|
||||
String sValue = (String)map.get("conf.xml.log.cache.value");
|
||||
try {
|
||||
if ((sValue == null) || (sValue.trim().equals(""))) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Value is NULL. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
this.value = Integer.parseInt(sValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Value is only support Integer[" + sValue + "]. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.value < 1) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Now log cache always saved. :: Log cache value is " + this.value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.type.trim().equalsIgnoreCase("SIZE"))
|
||||
{
|
||||
this.folderSize = this.value;
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "Log cache managed by Directory Volume. :: " + this.value + "/MB");
|
||||
} else if (this.type.trim().equalsIgnoreCase("DAY"))
|
||||
{
|
||||
this.cachePeriod = this.value;
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "Log cache managed by creation period of File. :: " + this.value + "/Day");
|
||||
}
|
||||
|
||||
this.timerRepeat = 21600000L;
|
||||
this.timer.cancel();
|
||||
this.timer = new Timer();
|
||||
this.timer.scheduleAtFixedRate(new CacheTimerTask(), 600000L, this.timerRepeat);
|
||||
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.timer.cancel();
|
||||
this.timer.purge();
|
||||
}
|
||||
|
||||
class CacheTimerTask extends TimerTask
|
||||
{
|
||||
CacheTimerTask() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "------------------------------");
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Run log cache management");
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "------------------------------");
|
||||
|
||||
if (LogCacheManager.this.type.equalsIgnoreCase("SIZE"))
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Check Directory volume. Every " + LogCacheManager.this.timerRepeat / 1000L / 60L + "/min, Limits " + LogCacheManager.this.folderSize + "MB");
|
||||
|
||||
ArrayList fileList = new ArrayList();
|
||||
readFile(fileList, LogCacheManager.this.logDir);
|
||||
|
||||
double cacheSize = getFileSize(fileList);
|
||||
double size = LogCacheManager.this.folderSize * 1024L * 1024L;
|
||||
|
||||
if (size < cacheSize)
|
||||
{
|
||||
Collections.sort(fileList, new FileComparator());
|
||||
|
||||
for (int i = 0; i < fileList.size(); i++) {
|
||||
if (fileList.size() <= 4)
|
||||
{
|
||||
break;
|
||||
}
|
||||
File dFile = (File)fileList.get(i);
|
||||
if ((dFile.exists()) && (dFile.isFile()))
|
||||
{
|
||||
cacheSize -= ((File)fileList.get(i)).length();
|
||||
|
||||
dFile.delete();
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Remove log cache by Size. [" + dFile + "]");
|
||||
|
||||
fileList.remove(i);
|
||||
i--;
|
||||
|
||||
if ((dFile.getParentFile().isDirectory()) && (dFile.getParentFile().list().length == 0)) {
|
||||
File pFile = dFile.getParentFile();
|
||||
dFile = null;
|
||||
pFile.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (size > cacheSize)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (LogCacheManager.this.type.equalsIgnoreCase("DAY"))
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Check creation time of File. Every " + LogCacheManager.this.timerRepeat / 1000L / 60L + "/min, Limits " + LogCacheManager.this.cachePeriod + "Days");
|
||||
|
||||
ArrayList fileList = new ArrayList();
|
||||
readFile(fileList, LogCacheManager.this.logDir);
|
||||
Collections.sort(fileList, new FileComparator());
|
||||
|
||||
long time = 86400000L * LogCacheManager.this.cachePeriod;
|
||||
|
||||
for (int i = 0; i < fileList.size(); i++)
|
||||
{
|
||||
if (fileList.size() <= 4)
|
||||
{
|
||||
break;
|
||||
}
|
||||
File dFile = (File)fileList.get(i);
|
||||
if (time >= System.currentTimeMillis() - dFile.lastModified())
|
||||
break;
|
||||
if ((dFile.exists()) && (dFile.isFile())) {
|
||||
dFile.delete();
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Remove log cache by Day. [" + dFile + "]");
|
||||
|
||||
fileList.remove(i);
|
||||
i--;
|
||||
|
||||
if ((dFile.getParentFile().isDirectory()) && (dFile.getParentFile().list().length == 0)) {
|
||||
File pFile = dFile.getParentFile();
|
||||
dFile = null;
|
||||
pFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readFile(ArrayList<File> list, File file)
|
||||
{
|
||||
if (file.exists())
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
File[] files = file.listFiles();
|
||||
if ((files == null) || (files.length == 0))
|
||||
file.delete();
|
||||
else {
|
||||
for (int i = 0; i < files.length; i++)
|
||||
readFile(list, files[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double getFileSize(ArrayList<File> list)
|
||||
{
|
||||
double size = 0.0D;
|
||||
for (File file : list) {
|
||||
size += file.length();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
|
||||
public class LogMngr
|
||||
{
|
||||
public static final String LOG_TYPE_CONFIG = "[CONFIG]";
|
||||
public static final String LOG_TYPE_LICENSE = "[LICENSE]";
|
||||
public static final String LOG_TYPE_DB = "[DB]";
|
||||
public static final String LOG_TYPE_SERVER = "[SERVER]";
|
||||
public static final String LOG_TYPE_MAP = "[MAP]";
|
||||
public static final String LOG_TYPE_LAYER = "[LAYER]";
|
||||
public static final String LOG_TYPE_JDBC = "[JDBC]";
|
||||
public static final String LOG_TYPE_SHP = "[SHAPE]";
|
||||
public static final String LOG_TYPE_GML = "[GML]";
|
||||
public static final String LOG_TYPE_GWAVE = "[GWAVE]";
|
||||
public static final String LOG_TYPE_WMTS = "[WMTS]";
|
||||
public static final String LOG_TYPE_TMS = "[TMS]";
|
||||
public static final String LOG_TYPE_O2WPS = "[O2WPS]";
|
||||
public static final String LOG_TYPE_IMGCACHE = "[IMGCACHE]";
|
||||
public static final String LOG_TYPE_O2IMG = "[O2IMG]";
|
||||
public static final String LOG_TYPE_O2DEM = "[O2DEM]";
|
||||
public static final String LOG_TYPE_O2INFO = "[O2INFO]";
|
||||
public static final String LOG_TYPE_O2INDEX = "[O2INDEX]";
|
||||
public static final String LOG_TYPE_SERVICE = "[SERVICE]";
|
||||
public static final String LOG_TYPE_REQUEST = "[REQUEST]";
|
||||
public static final String LOG_TYPE_RESPONSE = "[RESPONSE]";
|
||||
public static final String LOG_TYPE_FILE = "[FILE]";
|
||||
public static final String LOG_TYPE_CACHE = "[CACHE]";
|
||||
public static final String LOG_TYPE_FEATURE = "[FEATURE]";
|
||||
public static final String LOG_TYPE_RENDER = "[RENDER]";
|
||||
public static final String LOG_TYPE_STYLE = "[STYLE]";
|
||||
public static final String LOG_TYPE_CRS = "[CRS]";
|
||||
private static LogMngr instance = null;
|
||||
|
||||
private File logDir = null;
|
||||
|
||||
private Level logLevel = null;
|
||||
private Level reqLevel = null;
|
||||
|
||||
private Logger logger = null;
|
||||
private Logger loggerRequest = null;
|
||||
|
||||
private LogMngr() {
|
||||
initLog(null);
|
||||
}
|
||||
|
||||
public static LogMngr getInstance()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new LogMngr();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void initLog(HashMap<String, Object> map)
|
||||
{
|
||||
this.logDir = null;
|
||||
|
||||
if (map == null) {
|
||||
System.out.println("*********************************");
|
||||
System.out.println("Init LogMngr");
|
||||
System.out.println("*********************************");
|
||||
map = new HashMap();
|
||||
} else {
|
||||
System.out.println("*********************************");
|
||||
System.out.println("Setup logging option for LogMngr");
|
||||
System.out.println("*********************************");
|
||||
}
|
||||
|
||||
String lValue = (String)map.get("conf.xml.log.level");
|
||||
if (ServerUtil.isNullString(lValue)) {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Log level value is null. Setup Logging basic [IFNO] level.");
|
||||
} else {
|
||||
lValue = lValue.trim().toUpperCase();
|
||||
if (lValue.equalsIgnoreCase("DEBUG")) {
|
||||
this.logLevel = Level.DEBUG;
|
||||
System.out.println("- Now Logging DEBUG level.");
|
||||
} else if (lValue.equalsIgnoreCase("INFO")) {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Now Logging INFO level.");
|
||||
} else if (lValue.equalsIgnoreCase("ERROR")) {
|
||||
this.logLevel = Level.ERROR;
|
||||
System.out.println("- Now Logging ERROR level.");
|
||||
} else if (lValue.equalsIgnoreCase("FATAL")) {
|
||||
this.logLevel = Level.FATAL;
|
||||
System.out.println("- Now Logging FATAL level.");
|
||||
}
|
||||
else {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Now Logging basic [IFNO] level.");
|
||||
}
|
||||
}
|
||||
|
||||
String rValue = (String)map.get("conf.xml.log.request");
|
||||
if (ServerUtil.getBooleanValue(rValue)) {
|
||||
this.reqLevel = Level.INFO;
|
||||
System.out.println("- Request log level value is TRUE.");
|
||||
} else {
|
||||
this.reqLevel = Level.ERROR;
|
||||
System.out.println("- Request log level value is FALSE.");
|
||||
}
|
||||
|
||||
String dValue = (String)map.get("conf.xml.log.dir");
|
||||
if (ServerUtil.isNullString(dValue))
|
||||
{
|
||||
this.logDir = null;
|
||||
System.out.println("- Log file location[Directory name] is null. Now use only console logging.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logDir = new File(dValue.trim());
|
||||
if (this.logDir.exists())
|
||||
{
|
||||
if (this.logDir.isDirectory()) {
|
||||
this.logDir.setExecutable(true, false);
|
||||
this.logDir.setReadable(true);
|
||||
this.logDir.setWritable(true);
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is activate.");
|
||||
} else {
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is not Directory. Now use only console logging.");
|
||||
this.logDir = null;
|
||||
}
|
||||
|
||||
}
|
||||
else if (this.logDir.mkdirs()) {
|
||||
this.logDir.setExecutable(true, false);
|
||||
this.logDir.setReadable(true);
|
||||
this.logDir.setWritable(true);
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is activate.");
|
||||
} else {
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is not available. Now use only console logging.");
|
||||
this.logDir = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
initLogger();
|
||||
}
|
||||
|
||||
private void initLogger()
|
||||
{
|
||||
Properties prop = new Properties();
|
||||
|
||||
prop.setProperty("log4j.rootLogger", "OFF");
|
||||
|
||||
prop.setProperty("log4j.logger.o2map.log", "INFO,stdout");
|
||||
prop.setProperty("log4j.logger.o2map.request", "INFO,stdout");
|
||||
|
||||
prop.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
|
||||
prop.setProperty("log4j.appender.stdout.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.stdout.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} [%c{1}] > %p - %m%n");
|
||||
|
||||
if (this.logDir != null)
|
||||
{
|
||||
prop.setProperty("log4j.appender.o2log", "org.apache.log4j.DailyRollingFileAppender");
|
||||
prop.setProperty("log4j.appender.o2log.File", this.logDir.getAbsolutePath() + "/" + "o2map.log");
|
||||
prop.setProperty("log4j.appender.o2log.Append", "true");
|
||||
prop.setProperty("log4j.appender.o2log.DatePattern", "'.'yyyy-MM-dd-HH");
|
||||
prop.setProperty("log4j.appender.o2log.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.o2log.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} > %p - %m%n");
|
||||
|
||||
prop.setProperty("log4j.appender.request", "org.apache.log4j.DailyRollingFileAppender");
|
||||
prop.setProperty("log4j.appender.request.File", this.logDir.getAbsolutePath() + "/" + "o2map_request.log");
|
||||
prop.setProperty("log4j.appender.request.Append", "true");
|
||||
prop.setProperty("log4j.appender.request.DatePattern", "'.'yyyy-MM-dd-HH");
|
||||
prop.setProperty("log4j.appender.request.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.request.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} > %p - %m%n");
|
||||
|
||||
prop.setProperty("log4j.logger.o2map.log", "INFO,stdout,o2log");
|
||||
if (this.reqLevel == Level.INFO) {
|
||||
prop.setProperty("log4j.logger.o2map.request", "INFO,stdout,request");
|
||||
}
|
||||
}
|
||||
|
||||
PropertyConfigurator.configure(prop);
|
||||
|
||||
this.logger = Logger.getLogger("o2map.log");
|
||||
this.loggerRequest = Logger.getLogger("o2map.request");
|
||||
|
||||
this.logger.setLevel(this.logLevel);
|
||||
this.loggerRequest.setLevel(this.reqLevel);
|
||||
}
|
||||
|
||||
public void reqInfo(String logType, String message)
|
||||
{
|
||||
this.loggerRequest.info(logType + " " + message);
|
||||
}
|
||||
|
||||
public void logDebug(String logType, String message)
|
||||
{
|
||||
this.logger.debug(logType + " " + message);
|
||||
}
|
||||
|
||||
public void logInfo(String logType, String message) {
|
||||
this.logger.info(logType + " " + message);
|
||||
}
|
||||
|
||||
public void logWarn(String logType, String message) {
|
||||
this.logger.warn(logType + " " + message);
|
||||
}
|
||||
|
||||
public void logError(String logType, String message) {
|
||||
this.logger.error(logType + " " + message);
|
||||
}
|
||||
|
||||
public void logFatal(String logType, String message) {
|
||||
this.logger.fatal(logType + " " + message);
|
||||
}
|
||||
|
||||
public File getLogDirctory()
|
||||
{
|
||||
return this.logDir;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Map
|
||||
{
|
||||
private final String mapName;
|
||||
private final String mapNameSpace;
|
||||
private LayerSet serviceLayerSet;
|
||||
private O2WpsLayerSet o2wpsLayerSet;
|
||||
|
||||
public Map(String name, String ns)
|
||||
throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
throw new IllegalArgumentException("Map Name [" + name + "] is NULL.");
|
||||
}
|
||||
|
||||
this.mapName = name.trim().toUpperCase();
|
||||
|
||||
if (!ServerUtil.isNullString(ns))
|
||||
{
|
||||
ns = ns.trim();
|
||||
|
||||
if ((ns.equalsIgnoreCase("NULL")) || (ns.equalsIgnoreCase("DEFAULT")))
|
||||
this.mapNameSpace = null;
|
||||
else
|
||||
this.mapNameSpace = ns;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.mapNameSpace = null;
|
||||
}
|
||||
|
||||
this.serviceLayerSet = new LayerSet(this);
|
||||
this.o2wpsLayerSet = new O2WpsLayerSet(WpsVecStoreMngr.O2WpsMetaTableType.LAYERINFO_TBL.toString());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.mapName;
|
||||
}
|
||||
|
||||
public boolean useNameSpace() {
|
||||
if (ServerUtil.isNullString(this.mapNameSpace)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getNameSpace()
|
||||
{
|
||||
if (useNameSpace()) {
|
||||
return this.mapName.toLowerCase();
|
||||
}
|
||||
|
||||
return "sf";
|
||||
}
|
||||
|
||||
public String getNameSpaceURI()
|
||||
{
|
||||
if (useNameSpace()) {
|
||||
return this.mapNameSpace;
|
||||
}
|
||||
|
||||
return "http://cite.opengeospatial.org/gmlsf";
|
||||
}
|
||||
|
||||
public LayerSet getServiceLayerSet() {
|
||||
return this.serviceLayerSet;
|
||||
}
|
||||
|
||||
public O2WpsLayerSet getO2WpsLayerSet() {
|
||||
return this.o2wpsLayerSet;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getAllLayers() {
|
||||
ArrayList layers = new ArrayList();
|
||||
layers.addAll(this.serviceLayerSet.getLayers());
|
||||
layers.addAll(this.o2wpsLayerSet.getLayers());
|
||||
return layers;
|
||||
}
|
||||
|
||||
public Layer getLayer(String name) throws Exception
|
||||
{
|
||||
try {
|
||||
return this.serviceLayerSet.getLayer(name);
|
||||
} catch (Exception e) {
|
||||
Layer layer = this.o2wpsLayerSet.getLayer(name);
|
||||
if (layer != null) return layer;
|
||||
|
||||
layer = this.o2wpsLayerSet.getLayer(WpsVecStoreMngr.O2WpsMetaTableType.STORELYRINFO_TBL.getName(), name);
|
||||
if (layer != null) return layer;
|
||||
|
||||
return this.o2wpsLayerSet.getLayer(WpsVecStoreMngr.O2WpsMetaTableType.SHARELYRINFO_TBL.getName(), name);
|
||||
}
|
||||
}
|
||||
|
||||
public Layer getLayer(String storeTableName, String name)
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.o2wpsLayerSet.getLayer(storeTableName, name); } catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.geotools.styling.StyleImpl;
|
||||
|
||||
public class MapStyle
|
||||
extends StyleImpl {
|
||||
private LayerFactory.LayerType layerType;
|
||||
private String serverName;
|
||||
private String typeName;
|
||||
private Double wrapTileText;
|
||||
|
||||
public MapStyle() {
|
||||
this.setName("");
|
||||
if (this.getDescription() != null) {
|
||||
this.getDescription().setTitle("");
|
||||
this.getDescription().setAbstract("");
|
||||
}
|
||||
}
|
||||
|
||||
public void setLayerType(LayerFactory.LayerType lType) {
|
||||
this.layerType = lType;
|
||||
}
|
||||
|
||||
public LayerFactory.LayerType getLayerType() {
|
||||
return this.layerType;
|
||||
}
|
||||
|
||||
public void setServerName(String sName) {
|
||||
this.serverName = sName.toUpperCase();
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return this.serverName;
|
||||
}
|
||||
|
||||
public void setTypeName(String tName) {
|
||||
this.typeName = tName.toUpperCase();
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return this.typeName;
|
||||
}
|
||||
|
||||
public boolean isWrapTileTextStyle() {
|
||||
return this.wrapTileText != null && !(this.wrapTileText <= 0.0);
|
||||
}
|
||||
|
||||
public double getWrapTileText() {
|
||||
if (this.wrapTileText == null || this.wrapTileText <= 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
return this.wrapTileText;
|
||||
}
|
||||
|
||||
public void setWrapTileText(double dValue) {
|
||||
if (dValue > 1.0) {
|
||||
dValue = 1.0;
|
||||
}
|
||||
if (this.wrapTileText == null || this.wrapTileText <= 0.0) {
|
||||
this.wrapTileText = dValue;
|
||||
} else if (this.wrapTileText < dValue) {
|
||||
this.wrapTileText = dValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Component
|
||||
public class MyStartServer implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
// 로깅을 위한 Logger 인스턴스
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MyStartServer.class);
|
||||
|
||||
/**
|
||||
* ContextRefreshedEvent가 발생했을 때 호출되는 메서드입니다.
|
||||
* 이 이벤트는 모든 빈이 로드되고 초기화된 후 애플리케이션 컨텍스트가 성공적으로 새로고침되었을 때 발생합니다.
|
||||
*
|
||||
* @param event 발생한 ContextRefreshedEvent
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
// 부모 컨텍스트에도 이벤트가 발생할 수 있으므로, 최상위(루트) 컨텍스트에서만 실행되도록 확인합니다.
|
||||
// 이는 중복 실행을 방지합니다.
|
||||
if (event.getApplicationContext().getParent() == null) {
|
||||
LOGGER.info("**************************************");
|
||||
LOGGER.info("* *");
|
||||
LOGGER.info("* WMS 서버 시작 *");
|
||||
LOGGER.info("* *");
|
||||
LOGGER.info("**************************************");
|
||||
|
||||
// 여기에 서버 시작 시 실행하고 싶은 다른 로직을 추가할 수 있습니다.
|
||||
// 예: 초기 데이터 로드, 스케줄러 시작 등
|
||||
|
||||
if (ServerConfiguration.getInstance().startServer())
|
||||
ServerInfo.getInstance().setStarted(true);
|
||||
else {
|
||||
ServerInfo.getInstance().setStarted(false);
|
||||
}
|
||||
|
||||
ServiceMngr.initServices();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,737 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.tmax.tibero.jdbc.TbBlob;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LinearRing;
|
||||
import com.vividsolutions.jts.io.WKBWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.geometry.jts.JTS;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||
import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class NonSpatialDialect extends PreparedStatementSQLDialect
|
||||
implements O2SqlDialect
|
||||
{
|
||||
final String O2SERVER_BOUND_KEY_START = "?S?";
|
||||
final String O2SERVER_BOUND_KEY_END = "?E?";
|
||||
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
||||
final String serverName;
|
||||
final String dbType;
|
||||
public ConcurrentHashMap<String, Double> gridStore = new ConcurrentHashMap();
|
||||
|
||||
ThreadLocal<WKBAttributeIO> wkbReader = new ThreadLocal();
|
||||
|
||||
public NonSpatialDialect(String name, String type, JDBCDataStore dataStore)
|
||||
{
|
||||
super(dataStore);
|
||||
this.serverName = name;
|
||||
this.dbType = type;
|
||||
}
|
||||
|
||||
public Class<?> getMapping(ResultSet columnMetaData, Connection cx)
|
||||
throws SQLException
|
||||
{
|
||||
String typeName = columnMetaData.getString("TYPE_NAME");
|
||||
|
||||
if ("blob".equalsIgnoreCase(typeName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Class gemetry = lookupGeometryType(columnMetaData, cx);
|
||||
|
||||
if (gemetry != null) {
|
||||
return gemetry;
|
||||
}
|
||||
}
|
||||
catch (IOException localIOException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx)
|
||||
throws SQLException, IOException
|
||||
{
|
||||
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
||||
String tableName = columnMetaData.getString("TABLE_NAME");
|
||||
String columnName = columnMetaData.getString("COLUMN_NAME");
|
||||
|
||||
lookupGridSize(cx, schemaName, tableName, columnName);
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
||||
|
||||
if ((schemaName == null) || (schemaName.equals("")))
|
||||
schemaName = "";
|
||||
else {
|
||||
schemaName = schemaName.toUpperCase() + ".";
|
||||
}
|
||||
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
|
||||
if (rs.next())
|
||||
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
||||
} catch (Exception localException) {
|
||||
}
|
||||
finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT ");
|
||||
sql.append(columnName.toUpperCase());
|
||||
sql.append(" FROM ");
|
||||
sql.append(schemaName).append(tableName.toUpperCase());
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
|
||||
if ((rs != null) && (rs.next())) {
|
||||
Geometry geom = decodeGeometryValue(null, rs, columnName, new GeometryFactory(), cx);
|
||||
Class localClass2 = O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType()); return localClass2;
|
||||
}
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void lookupGridSize(Connection cx, String schemaName, String tableName, String columnName)
|
||||
throws SQLException, IOException
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[DB]", "Lookup GridSize for [" + tableName + "]");
|
||||
|
||||
String gridKey = tableName.trim().toUpperCase() + "_" + columnName.trim().toUpperCase();
|
||||
|
||||
if (this.gridStore.get(gridKey) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((schemaName == null) || (schemaName.equals("")))
|
||||
schemaName = "";
|
||||
else {
|
||||
schemaName = schemaName.toUpperCase() + ".";
|
||||
}
|
||||
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT GRID_SIZE FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.trim().toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.trim().toUpperCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if ((rs != null) && (rs.next())) {
|
||||
double grid = rs.getDouble(1);
|
||||
this.gridStore.put(gridKey, Double.valueOf(grid));
|
||||
} else {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"Failed to get GridSize from O2SERVER_GEOMETRY_LAYER for [" +
|
||||
tableName.trim().toUpperCase() + "/" + columnName.trim().toUpperCase() + "]");
|
||||
throw new IOException("GridSize is NULL for [" + tableName.trim().toUpperCase() + "/" + columnName.trim().toUpperCase() + "]");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
|
||||
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings)
|
||||
{
|
||||
super.registerSqlTypeNameToClassMappings(mappings);
|
||||
|
||||
mappings.put("TEXT", String.class);
|
||||
mappings.put("text", String.class);
|
||||
}
|
||||
|
||||
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings)
|
||||
{
|
||||
super.registerSqlTypeToClassMappings(mappings);
|
||||
}
|
||||
|
||||
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx)
|
||||
throws SQLException
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
||||
|
||||
if ((schemaName == null) || (schemaName.equals("")))
|
||||
schemaName = "";
|
||||
else {
|
||||
schemaName = schemaName.toUpperCase() + ".";
|
||||
}
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
Integer localInteger;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("SELECT REF_SRID FROM ");
|
||||
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
||||
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
||||
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
||||
rs = stat.executeQuery(sb.toString());
|
||||
|
||||
if ((rs != null) && (rs.next())) {
|
||||
Object obj = rs.getObject(1);
|
||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" +
|
||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT SRID FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
|
||||
if ((rs != null) && (rs.next())) {
|
||||
Object obj = rs.getObject(1);
|
||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" +
|
||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
||||
return this.DEFAULT_CRS;
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException
|
||||
{
|
||||
try {
|
||||
return CRSMngr.getLayerCRS(srid, true); } catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isLimitOffsetSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void applyLimitOffset(StringBuffer sql, int limit, int offset)
|
||||
{
|
||||
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ALTIBASE.getTypeName()))
|
||||
{
|
||||
if ((limit >= 0) && (limit < 2147483647)) {
|
||||
sql.append(" LIMIT " + limit);
|
||||
if (offset > 0)
|
||||
sql.append(" OFFSET " + offset);
|
||||
}
|
||||
else if (offset > 0) {
|
||||
sql.append(" OFFSET " + offset);
|
||||
}
|
||||
}
|
||||
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.TIBERO.getTypeName()))
|
||||
{
|
||||
if (offset == 0)
|
||||
{
|
||||
sql.insert(0, "SELECT * FROM (");
|
||||
sql.append(") WHERE ROWNUM <= " + limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
long max = limit == 2147483647 ? 9223372036854775807L : limit + offset;
|
||||
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||
sql.append("WHERE RNUM > " + offset);
|
||||
}
|
||||
}
|
||||
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ORACLE.getTypeName()))
|
||||
{
|
||||
if (offset == 0)
|
||||
{
|
||||
sql.insert(0, "SELECT * FROM (");
|
||||
sql.append(") WHERE ROWNUM <= " + limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
long max = limit == 2147483647 ? 9223372036854775807L : limit + offset;
|
||||
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||
sql.append("WHERE RNUM > " + offset);
|
||||
}
|
||||
}
|
||||
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.MYSQL.getTypeName()))
|
||||
{
|
||||
if ((limit >= 0) && (limit < 2147483647)) {
|
||||
if (offset > 0)
|
||||
sql.append(" LIMIT " + offset + ", " + limit);
|
||||
else
|
||||
sql.append(" LIMIT " + limit);
|
||||
} else if (offset > 0)
|
||||
{
|
||||
sql.append(" LIMIT " + offset + ", " + 9223372036854775807L);
|
||||
}
|
||||
}
|
||||
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.POSTGIS.getTypeName()))
|
||||
{
|
||||
if ((limit >= 0) && (limit < 2147483647)) {
|
||||
sql.append(" LIMIT " + limit);
|
||||
if (offset > 0)
|
||||
sql.append(" OFFSET " + offset);
|
||||
}
|
||||
else if (offset > 0) {
|
||||
sql.append(" OFFSET " + offset);
|
||||
}
|
||||
}
|
||||
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.KAIROS.getTypeName()))
|
||||
{
|
||||
if ((limit >= 0) && (limit < 2147483647)) {
|
||||
if (offset > 0)
|
||||
sql.append(" LIMIT " + offset + ", " + limit);
|
||||
else
|
||||
sql.append(" LIMIT " + limit);
|
||||
} else if (offset > 0)
|
||||
sql.append(" LIMIT " + offset + ", " + 9223372036854775807L);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
||||
throws SQLException, IOException
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||
|
||||
List resultList = new ArrayList();
|
||||
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
String schema = "";
|
||||
if ((schemaName == null) || (schemaName.equals("")))
|
||||
schema = "";
|
||||
else {
|
||||
schema = schemaName + ".";
|
||||
}
|
||||
schema = schema.toUpperCase();
|
||||
|
||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||
if ((att instanceof GeometryDescriptor))
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
||||
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE");
|
||||
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
||||
sql.append(" AND");
|
||||
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
|
||||
if ((rs != null) && (rs.next())) {
|
||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||
double x1 = rs.getDouble(1);
|
||||
double x2 = rs.getDouble(2);
|
||||
double y1 = rs.getDouble(3);
|
||||
double y2 = rs.getDouble(4);
|
||||
|
||||
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
List localList1;
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
||||
return getInternalBounds(schemaName, featureType, cx);
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||
|
||||
List resultList = new ArrayList();
|
||||
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
if ((schemaName == null) || (schemaName.equals("")))
|
||||
schemaName = "";
|
||||
else {
|
||||
schemaName = schemaName + ".";
|
||||
}
|
||||
schemaName = schemaName.toUpperCase();
|
||||
|
||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||
if ((att instanceof GeometryDescriptor))
|
||||
{
|
||||
String tableName = featureType.getTypeName() + "_" + att.getLocalName() + "_INDEX";
|
||||
tableName.toUpperCase();
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT MIN(MIN_1D), MAX(MAX_1D), MIN(MIN_2D), MAX(MAX_2D) FROM ");
|
||||
sql.append(schemaName).append(tableName);
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
|
||||
if ((rs != null) && (rs.next())) {
|
||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||
double x1 = rs.getDouble(1);
|
||||
double x2 = rs.getDouble(2);
|
||||
double y1 = rs.getDouble(3);
|
||||
double y2 = rs.getDouble(4);
|
||||
|
||||
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql)
|
||||
{
|
||||
String envelopeTable = null;
|
||||
if ((this.dataStore.getDatabaseSchema() == null) || (this.dataStore.getDatabaseSchema().equals("")))
|
||||
envelopeTable = tableName + "_" + geometryColumn + "_INDEX";
|
||||
else {
|
||||
envelopeTable = this.dataStore.getDatabaseSchema() + "." + tableName + "_" + geometryColumn + "_INDEX";
|
||||
}
|
||||
envelopeTable = envelopeTable.toUpperCase();
|
||||
|
||||
sql.append("?S?");
|
||||
sql.append(envelopeTable);
|
||||
sql.append("?E?");
|
||||
sql.append(" MIN(MIN_1D), MAX(MAX_1D), MIN(MIN_2D), MAX(MAX_2D) ");
|
||||
}
|
||||
|
||||
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx)
|
||||
throws SQLException, IOException
|
||||
{
|
||||
int count = rs.getMetaData().getColumnCount();
|
||||
int evnObject = count / 4 - 1;
|
||||
|
||||
if (evnObject + 1 == column)
|
||||
{
|
||||
double x1 = rs.getDouble(evnObject + 1);
|
||||
double x2 = rs.getDouble(evnObject + 2);
|
||||
double y1 = rs.getDouble(evnObject + 3);
|
||||
double y2 = rs.getDouble(evnObject + 4);
|
||||
|
||||
return new Envelope(x1, x2, y1, y2);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql)
|
||||
{
|
||||
super.prepareGeometryValue(g, dimension, srid, binding, sql);
|
||||
}
|
||||
|
||||
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
|
||||
throws SQLException
|
||||
{
|
||||
if (g != null) {
|
||||
if ((g instanceof LinearRing))
|
||||
{
|
||||
g = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||
}
|
||||
|
||||
WKBWriter wkbWriter = new WKBWriter(dimension);
|
||||
byte[] bytes = wkbWriter.write(g);
|
||||
|
||||
int length = bytes.length + getBytesSize(dimension);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(length);
|
||||
byte[] extentBytes = getExtentBytes(dimension, g);
|
||||
buffer.put(extentBytes);
|
||||
buffer.put(bytes);
|
||||
|
||||
buffer.rewind();
|
||||
byte[] o2Geom = new byte[length];
|
||||
buffer.get(o2Geom);
|
||||
|
||||
ps.setBytes(column, o2Geom);
|
||||
} else {
|
||||
ps.setNull(column, 1111, "GEOMETRY");
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getExtentBytes(int dimension, Geometry geom) {
|
||||
int bufferSize = dimension * 8 * 2 + 1;
|
||||
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
|
||||
|
||||
buffer.put((byte)dimension);
|
||||
|
||||
ReferencedEnvelope env = JTS.toEnvelope(geom);
|
||||
|
||||
if (dimension >= 1) {
|
||||
buffer.putDouble(env.getMinX());
|
||||
buffer.putDouble(env.getMaxX());
|
||||
}
|
||||
|
||||
if (dimension >= 2) {
|
||||
buffer.putDouble(env.getMinY());
|
||||
buffer.putDouble(env.getMaxY());
|
||||
}
|
||||
|
||||
if (dimension >= 3) {
|
||||
buffer.putDouble(0.0D);
|
||||
buffer.putDouble(0.0D);
|
||||
}
|
||||
|
||||
if (dimension >= 4) {
|
||||
buffer.putDouble(0.0D);
|
||||
buffer.putDouble(0.0D);
|
||||
}
|
||||
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx)
|
||||
throws IOException, SQLException
|
||||
{
|
||||
byte[] bytes = getBytes(rs.getBlob(column));
|
||||
|
||||
int size = getBytesSize(bytes[0]);
|
||||
byte[] newBytes = new byte[bytes.length - size];
|
||||
|
||||
System.arraycopy(bytes, size, newBytes, 0, newBytes.length);
|
||||
|
||||
WKBAttributeIO reader = getWKBReader(factory);
|
||||
Geometry geom = reader.read(newBytes);
|
||||
|
||||
return geom;
|
||||
}
|
||||
|
||||
public byte[] getBytes(Blob blob) throws SQLException, IOException
|
||||
{
|
||||
InputStream blobStream = null;
|
||||
ByteArrayOutputStream outStream = null;
|
||||
try
|
||||
{
|
||||
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.TIBERO.getTypeName())) {
|
||||
TbBlob tbblob = (TbBlob)blob;
|
||||
blobStream = tbblob.getBinaryStream();
|
||||
} else {
|
||||
blobStream = blob.getBinaryStream();
|
||||
}
|
||||
|
||||
outStream = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int nbytes = 0;
|
||||
while ((nbytes = blobStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, nbytes);
|
||||
}
|
||||
return outStream.toByteArray();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ORACLE.getTypeName())) {
|
||||
blob.free();
|
||||
}
|
||||
|
||||
if (blobStream != null) {
|
||||
blobStream.close();
|
||||
}
|
||||
if (outStream != null)
|
||||
outStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBytesSize(int dimension)
|
||||
{
|
||||
return 1 + 16 * dimension;
|
||||
}
|
||||
|
||||
private WKBAttributeIO getWKBReader(GeometryFactory factory)
|
||||
{
|
||||
WKBAttributeIO reader = (WKBAttributeIO)this.wkbReader.get();
|
||||
if (reader == null) {
|
||||
reader = new WKBAttributeIO(factory);
|
||||
this.wkbReader.set(reader);
|
||||
} else {
|
||||
reader.setGeometryFactory(factory);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
public PreparedFilterToSQL createPreparedFilterToSQL()
|
||||
{
|
||||
return new NonSpatialFilterToSQL(this);
|
||||
}
|
||||
|
||||
public boolean lookupGeneratedValuesPostInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType)
|
||||
throws SQLException
|
||||
{
|
||||
select.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||
{
|
||||
delete.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||
{
|
||||
insert.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||
{
|
||||
update.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void encodeSchemaName(String raw, StringBuffer sql)
|
||||
{
|
||||
super.encodeSchemaName(raw, sql);
|
||||
}
|
||||
|
||||
public void encodeTableName(String raw, StringBuffer sql)
|
||||
{
|
||||
if (sql.indexOf("?S?") != -1) {
|
||||
int sIndex = sql.indexOf("?S?");
|
||||
int eIndex = sql.indexOf("?E?") + "?E?".length();
|
||||
String tableName = sql.substring(sIndex, eIndex);
|
||||
tableName = tableName.replace("?S?", "");
|
||||
tableName = tableName.replace("?E?", "");
|
||||
|
||||
sql.delete(sIndex, eIndex);
|
||||
sql.append(tableName);
|
||||
} else {
|
||||
super.encodeTableName(raw, sql);
|
||||
}
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
}
|
||||
|
||||
public void encodeColumnName(String prefix, String raw, StringBuffer sql)
|
||||
{
|
||||
if (prefix != null) {
|
||||
sql.append(prefix).append(".");
|
||||
}
|
||||
sql.append(raw);
|
||||
}
|
||||
|
||||
public String getNameEscape()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public JDBCDataStore getDataStore()
|
||||
{
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
public String getDbType()
|
||||
{
|
||||
return this.dbType;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,303 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.Writer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.data.Transaction;
|
||||
import org.geotools.data.jdbc.FilterToSQL.FieldEncoder;
|
||||
import org.geotools.filter.FilterCapabilities;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.JoinPropertyName;
|
||||
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||
import org.geotools.jdbc.PrimaryKey;
|
||||
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||
import org.geotools.jdbc.SQLDialect;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.filter.expression.Literal;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
import org.opengis.filter.spatial.BBOX;
|
||||
import org.opengis.filter.spatial.BinarySpatialOperator;
|
||||
import org.opengis.geometry.BoundingBox;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
public class NonSpatialFilterToSQL extends PreparedFilterToSQL
|
||||
{
|
||||
private NonSpatialDialect dsDialectNS;
|
||||
|
||||
public NonSpatialFilterToSQL(NonSpatialDialect dialect)
|
||||
{
|
||||
this.dsDialectNS = dialect;
|
||||
}
|
||||
|
||||
protected FilterCapabilities createFilterCapabilities()
|
||||
{
|
||||
FilterCapabilities caps = new FilterCapabilities();
|
||||
caps.addAll(SQLDialect.BASE_DBMS_CAPABILITIES);
|
||||
|
||||
caps.addType(BBOX.class);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
protected Object visitBinarySpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((filter instanceof BBOX))
|
||||
createBBox(filter, property);
|
||||
else
|
||||
throw new RuntimeException("Unsupported filter type " + filter.getClass());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("Error to make BinarySpatialOperator", e);
|
||||
}
|
||||
|
||||
return extraData;
|
||||
}
|
||||
|
||||
private void createBBox(BinarySpatialOperator filter, PropertyName property)
|
||||
throws Exception
|
||||
{
|
||||
BBOX bbox = (BBOX)filter;
|
||||
Envelope envelop = ReferencedEnvelope.reference(bbox.getBounds());
|
||||
envelop = intersectionBound(envelop);
|
||||
|
||||
if ((envelop == null) || (envelop.isNull())) {
|
||||
this.out.append(" 1=0 ");
|
||||
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
String propertyName = findPropertyName(property);
|
||||
|
||||
String indexName = new String();
|
||||
if ((this.databaseSchema == null) || (this.databaseSchema.equals("")))
|
||||
indexName = this.featureType.getTypeName() + "_" + propertyName + "_INDEX";
|
||||
else {
|
||||
indexName = this.databaseSchema + "." + this.featureType.getTypeName() + "_" + propertyName + "_INDEX";
|
||||
}
|
||||
indexName = indexName.toUpperCase();
|
||||
|
||||
String pkCloumn = ((PrimaryKeyColumn)this.primaryKey.getColumns().get(0)).getName().toUpperCase();
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
try {
|
||||
GridRange gridRange = getIntersectRange(envelop, propertyName);
|
||||
|
||||
sql.append(" ").append(pkCloumn).append(" IN (");
|
||||
sql.append(" SELECT ").append(pkCloumn).append(" FROM ").append(indexName);
|
||||
sql.append(" WHERE ");
|
||||
sql.append(" COL_NUMBER >= ").append(String.valueOf(gridRange.sc)).append(" AND");
|
||||
sql.append(" COL_NUMBER <= ").append(String.valueOf(gridRange.ec)).append(" AND");
|
||||
sql.append(" ROW_NUMBER >= ").append(String.valueOf(gridRange.sr)).append(" AND");
|
||||
sql.append(" ROW_NUMBER <= ").append(String.valueOf(gridRange.er)).append(" AND");
|
||||
sql.append(" MAX_1D >= ").append(String.valueOf(envelop.getMinX())).append(" AND");
|
||||
sql.append(" MIN_1D <= ").append(String.valueOf(envelop.getMaxX())).append(" AND");
|
||||
sql.append(" MAX_2D >= ").append(String.valueOf(envelop.getMinY())).append(" AND");
|
||||
sql.append(" MIN_2D <= ").append(String.valueOf(envelop.getMaxY()));
|
||||
sql.append(" )");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sql = new StringBuffer();
|
||||
sql.append(" ").append(pkCloumn).append(" IN (");
|
||||
sql.append(" SELECT ").append(pkCloumn).append(" FROM ").append(indexName);
|
||||
sql.append(" WHERE ");
|
||||
sql.append(" MAX_1D >= ").append(String.valueOf(envelop.getMinX())).append(" AND");
|
||||
sql.append(" MIN_1D <= ").append(String.valueOf(envelop.getMaxX())).append(" AND");
|
||||
sql.append(" MAX_2D >= ").append(String.valueOf(envelop.getMinY())).append(" AND");
|
||||
sql.append(" MIN_2D <= ").append(String.valueOf(envelop.getMaxY()));
|
||||
sql.append(" )");
|
||||
}
|
||||
|
||||
this.out.append(sql);
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||
}
|
||||
|
||||
public String findPropertyName(PropertyName expression)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if ((expression instanceof JoinPropertyName))
|
||||
{
|
||||
sb.append(escapeName(((JoinPropertyName)expression).getAlias()));
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
AttributeDescriptor attribute = null;
|
||||
try {
|
||||
attribute = (AttributeDescriptor)expression.evaluate(this.featureType);
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
}
|
||||
String encodedField;
|
||||
if (attribute != null)
|
||||
encodedField = this.fieldEncoder.encode(escapeName(attribute.getLocalName()));
|
||||
else {
|
||||
encodedField = this.fieldEncoder.encode(escapeName(expression.getPropertyName()));
|
||||
}
|
||||
|
||||
sb.append(encodedField);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private Envelope intersectionBound(Envelope envelop)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||
for (Layer layer : layers)
|
||||
{
|
||||
if ((layer instanceof FeatureLayer))
|
||||
{
|
||||
if ((layer.getServerName().equalsIgnoreCase(this.dsDialectNS.serverName)) &&
|
||||
(layer.getSourceName().equalsIgnoreCase(this.featureType.getTypeName())))
|
||||
{
|
||||
return layer.getBBox().intersection(envelop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
}
|
||||
return envelop;
|
||||
}
|
||||
|
||||
private BoundingBox transformFilter(BoundingBox bound)
|
||||
{
|
||||
if (bound.getCoordinateReferenceSystem() == null) {
|
||||
return bound;
|
||||
}
|
||||
try
|
||||
{
|
||||
CoordinateReferenceSystem targetCRS = getCRS(this.featureType.getTypeName());
|
||||
if (!CRS.equalsIgnoreMetadata(targetCRS, bound.getCoordinateReferenceSystem()))
|
||||
return bound.toBounds(targetCRS);
|
||||
}
|
||||
catch (TransformException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bound;
|
||||
}
|
||||
|
||||
private CoordinateReferenceSystem getCRS(String typeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||
for (Layer layer : layers)
|
||||
{
|
||||
if ((layer instanceof FeatureLayer))
|
||||
{
|
||||
if (layer.getSourceName().equalsIgnoreCase(typeName))
|
||||
return layer.getCRS();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
}
|
||||
return CRSMngr.getCRS(Integer.valueOf(4326));
|
||||
}
|
||||
|
||||
private Double getGridSize(String typeName, String columnName)
|
||||
{
|
||||
String schemaName = null;
|
||||
if ((this.databaseSchema == null) || (this.databaseSchema.equals("")))
|
||||
schemaName = "";
|
||||
else {
|
||||
schemaName = this.databaseSchema.toUpperCase() + ".";
|
||||
}
|
||||
|
||||
Connection cx = null;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
cx = this.dsDialectNS.getDataStore().getConnection(Transaction.AUTO_COMMIT);
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT GRID_SIZE FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(typeName.toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if ((rs != null) && (rs.next()))
|
||||
return Double.valueOf(rs.getDouble(1));
|
||||
} catch (Exception localException) {
|
||||
}
|
||||
finally {
|
||||
this.dsDialectNS.getDataStore().closeSafe(cx);
|
||||
this.dsDialectNS.getDataStore().closeSafe(rs);
|
||||
this.dsDialectNS.getDataStore().closeSafe(stat);
|
||||
}
|
||||
this.dsDialectNS.getDataStore().closeSafe(cx);
|
||||
this.dsDialectNS.getDataStore().closeSafe(rs);
|
||||
this.dsDialectNS.getDataStore().closeSafe(stat);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private GridRange getIntersectRange(Envelope envelop, String columnName) throws Exception
|
||||
{
|
||||
String gridKey = this.featureType.getTypeName() + "_" + columnName;
|
||||
gridKey = gridKey.toUpperCase();
|
||||
|
||||
Double gridSize = (Double)this.dsDialectNS.gridStore.get(gridKey);
|
||||
|
||||
if (gridSize == null) {
|
||||
gridSize = getGridSize(this.featureType.getTypeName(), columnName);
|
||||
if (gridSize == null) return null;
|
||||
this.dsDialectNS.gridStore.put(gridKey, gridSize);
|
||||
}
|
||||
|
||||
return calIntersectRange(envelop, gridSize.doubleValue());
|
||||
}
|
||||
|
||||
private GridRange calIntersectRange(Envelope envelop, double gridSize) {
|
||||
if (gridSize <= 0.0D) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int sc = (int)(envelop.getMinX() / gridSize);
|
||||
int ec = (int)(envelop.getMinY() / gridSize);
|
||||
int sr = (int)(envelop.getMaxX() / gridSize);
|
||||
int er = (int)(envelop.getMaxY() / gridSize);
|
||||
|
||||
if (envelop.getMinX() < 0.0D) sc--;
|
||||
if (envelop.getMinY() < 0.0D) ec--;
|
||||
if (envelop.getMaxX() < 0.0D) sr--;
|
||||
if (envelop.getMaxY() < 0.0D) er--;
|
||||
|
||||
return new GridRange(sc, ec, sr, er); }
|
||||
private class GridRange { public int sc;
|
||||
public int ec;
|
||||
public int sr;
|
||||
public int er;
|
||||
|
||||
public GridRange(int start_col, int end_col, int start_row, int end_row) { this.sc = start_col;
|
||||
this.ec = end_col;
|
||||
this.sr = start_row;
|
||||
this.er = end_row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,434 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.text.ParseException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.factory.GeoTools;
|
||||
import org.geotools.metadata.iso.citation.CitationImpl;
|
||||
import org.geotools.metadata.iso.citation.Citations;
|
||||
import org.geotools.referencing.NamedIdentifier;
|
||||
import org.geotools.referencing.factory.DirectAuthorityFactory;
|
||||
import org.geotools.referencing.factory.ReferencingFactoryContainer;
|
||||
import org.geotools.referencing.wkt.Symbols;
|
||||
import org.geotools.util.SimpleInternationalString;
|
||||
import org.opengis.metadata.Identifier;
|
||||
import org.opengis.metadata.citation.Citation;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.IdentifiedObject;
|
||||
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||
import org.opengis.referencing.crs.CRSAuthorityFactory;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.util.InternationalString;
|
||||
|
||||
public class O2CRSFactory
|
||||
extends DirectAuthorityFactory
|
||||
implements CRSAuthorityFactory {
|
||||
private CitationImpl authority = new CitationImpl((CharSequence)"O2CRS");
|
||||
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
||||
private final Parser parser = new Parser();
|
||||
|
||||
public O2CRSFactory() {
|
||||
super(ReferencingFactoryContainer.instance(null), 99);
|
||||
this.initCrsDefinitions();
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException {
|
||||
HashSet<String> codes = new HashSet<String>();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
for (String key : this.definitions.keySet()) {
|
||||
String[] tempKeys = key.split("\\.");
|
||||
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
public InternationalString getDescriptionText(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||
CoordinateReferenceSystem crs = this.createCoordinateReferenceSystem(code);
|
||||
return new SimpleInternationalString(crs.toWKT());
|
||||
}
|
||||
|
||||
public Citation getAuthority() {
|
||||
return this.authority;
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||
if (ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("CRS code is NULL.");
|
||||
}
|
||||
String[] codes = code.split(":");
|
||||
if (codes.length == 2) {
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
String[] keyCodes = key.split("\\.");
|
||||
if (!keyCodes[1].equalsIgnoreCase(codes[0].trim()) || !keyCodes[2].equalsIgnoreCase(codes[1].trim())) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
} else if (codes.length == 1) {
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
String[] keyCodes = key.split("\\.");
|
||||
if (!keyCodes[2].equalsIgnoreCase(codes[0].trim())) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
} else {
|
||||
throw new NoSuchAuthorityCodeException("CRS code has problem : " + code, code, code);
|
||||
}
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code : " + code, codes[0], codes[1]);
|
||||
}
|
||||
|
||||
public void initCrsDefinitions() {
|
||||
block11: {
|
||||
Connection conn = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
try {
|
||||
conn = ConnMngr.getInstance().openConn();
|
||||
st = conn.createStatement();
|
||||
String sql = "SELECT * FROM O2SERVER_COORDINATE_SYSTEM";
|
||||
rs = st.executeQuery(sql);
|
||||
this.definitions.clear();
|
||||
while (rs.next()) {
|
||||
int srid = rs.getInt("SRID");
|
||||
String auth = rs.getString("AUTH_NAME");
|
||||
String code = rs.getString("AUTH_CODE");
|
||||
try {
|
||||
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
if (this.isContainSRID(srid)) {
|
||||
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||
}
|
||||
if (this.isContainCRS(auth, code)) {
|
||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||
}
|
||||
CoordinateReferenceSystem crs = this.parseWKT(auth, code, rs.getString("PARAMETER"));
|
||||
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||
this.addAuthority(auth);
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Success to add CRS [" + srid + "." + auth + "." + code + "] :: " + crs.toWKT());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Fail to add CRS [" + srid + "." + auth + "." + code + "] :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Can't access O2SERVER_COORDINATE_SYSTEM table :: " + e.getMessage());
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
break block11;
|
||||
}
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
throw throwable;
|
||||
}
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)wkt)) {
|
||||
throw new FactoryException("CRS WKT is NULL.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
Parser parser = this.parser;
|
||||
synchronized (parser) {
|
||||
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt.trim());
|
||||
}
|
||||
}
|
||||
|
||||
private void addAuthority(String auth) {
|
||||
Citation cit = Citations.fromName((String)auth);
|
||||
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
||||
}
|
||||
|
||||
private boolean isContainAuthority(String auth) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
throw new FactoryException("AUTHORITY is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
for (Identifier identifier : this.authority.getIdentifiers()) {
|
||||
if (!identifier.getCode().equalsIgnoreCase(auth)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
private boolean isContainSRID(int srid) throws Exception {
|
||||
if (srid < 0) {
|
||||
throw new FactoryException("SRID [" + srid + "] value is not available :: SRID >= 0");
|
||||
}
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String key;
|
||||
String id = Integer.toString(srid);
|
||||
Enumeration<String> keys = this.definitions.keys();
|
||||
do {
|
||||
if (keys.hasMoreElements()) continue;
|
||||
return false;
|
||||
} while (!(key = keys.nextElement()).split("\\.")[0].equalsIgnoreCase(id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
private boolean isContainCRS(String auth, String code) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
throw new FactoryException("AUTHORITY is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
if (ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("CODE is Null.");
|
||||
}
|
||||
code = code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String key;
|
||||
String[] codes;
|
||||
Enumeration<String> keys = this.definitions.keys();
|
||||
do {
|
||||
if (keys.hasMoreElements()) continue;
|
||||
return false;
|
||||
} while (!(codes = (key = keys.nextElement()).split("\\."))[1].equalsIgnoreCase(auth) || !codes[2].equalsIgnoreCase(code));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public String getCRSKey(int srid) throws Exception {
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String id = Integer.toString(srid);
|
||||
Enumeration<String> keys = this.definitions.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void insertCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||
if (this.isContainSRID(srid)) {
|
||||
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||
}
|
||||
if (this.isContainCRS(auth, code)) {
|
||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||
}
|
||||
if (crs == null) {
|
||||
throw new FactoryException("CRS is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
if (write) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("INSERT INTO O2SERVER_COORDINATE_SYSTEM ( SRID, AUTH_NAME, AUTH_CODE, PARAMETER) VALUES ( ");
|
||||
sb.append(srid).append(", ");
|
||||
sb.append("'").append(auth).append("', ");
|
||||
sb.append("'").append(code).append("', ");
|
||||
sb.append("'").append(crs.toWKT()).append("'");
|
||||
sb.append(" )");
|
||||
this.executeSQL(sb.toString());
|
||||
}
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||
this.addAuthority(auth);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean executeSQL(String sql) throws Exception {
|
||||
Connection conn = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = ConnMngr.getInstance().openConn();
|
||||
st = conn.createStatement();
|
||||
boolean bl = st.execute(sql);
|
||||
return bl;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "CRS execute fail :: " + e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
ConnMngr.getInstance().closeConn();
|
||||
ConnMngr.getInstance().closeSafe(rs);
|
||||
ConnMngr.getInstance().closeSafe(st);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void updateCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
throw new FactoryException("Authority value is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
if (ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("Code value is Null.");
|
||||
}
|
||||
code = code.trim().toUpperCase();
|
||||
if (crs == null) {
|
||||
throw new FactoryException("CRS value is Null.");
|
||||
}
|
||||
String[] ids = this.getCRSKey(srid).split("\\.");
|
||||
if (!(ids[1].equals(auth) && ids[2].equals(code) || !this.isContainCRS(auth, code))) {
|
||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||
}
|
||||
if (write) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("UPDATE O2SERVER_COORDINATE_SYSTEM SET ");
|
||||
sb.append("AUTH_NAME=").append("'").append(auth).append("'").append(", ");
|
||||
sb.append("AUTH_CODE=").append("'").append(code).append("'").append(", ");
|
||||
sb.append("PARAMETER=").append("'").append(crs.toWKT()).append("'").append(" ");
|
||||
sb.append("WHERE SRID=").append(srid);
|
||||
this.executeSQL(sb.toString());
|
||||
}
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String oldID = this.getCRSKey(srid);
|
||||
this.definitions.remove(oldID);
|
||||
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||
this.addAuthority(auth);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void removeCRS(int srid, boolean write) throws Exception {
|
||||
if (!this.isContainSRID(srid)) {
|
||||
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
||||
}
|
||||
if (write) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("DELETE FROM O2SERVER_COORDINATE_SYSTEM ");
|
||||
sb.append("WHERE SRID=").append(srid);
|
||||
this.executeSQL(sb.toString());
|
||||
}
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String id = Integer.toString(srid);
|
||||
for (String key : this.definitions.keySet()) {
|
||||
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||
this.definitions.remove(key);
|
||||
}
|
||||
GeoTools.fireConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public CoordinateReferenceSystem getCRS(int srid) throws NoSuchAuthorityCodeException {
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String id = Integer.toString(srid);
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
}
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public Set<String> getAuthorityCodes(String auth) {
|
||||
TreeSet<String> codes = new TreeSet<String>();
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
for (String key : this.definitions.keySet()) {
|
||||
String[] tempKeys = key.split("\\.");
|
||||
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
for (String key : this.definitions.keySet()) {
|
||||
String[] tempKeys = key.split("\\.");
|
||||
if (!tempKeys[1].equalsIgnoreCase(auth)) continue;
|
||||
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
private final class Parser
|
||||
extends org.geotools.referencing.wkt.Parser {
|
||||
private static final long serialVersionUID = -5910561042299146066L;
|
||||
private CitationImpl auth;
|
||||
private String code;
|
||||
|
||||
public Parser() {
|
||||
super(Symbols.DEFAULT, O2CRSFactory.this.factories);
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt) throws ParseException {
|
||||
this.auth = new CitationImpl(Citations.fromName((String)auth));
|
||||
this.code = code;
|
||||
return super.parseCoordinateReferenceSystem(wkt);
|
||||
}
|
||||
|
||||
protected Map<String, Object> alterProperties(Map<String, Object> properties) {
|
||||
properties.put("identifiers", new NamedIdentifier((Citation)this.auth, this.code));
|
||||
return super.alterProperties(properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,423 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
//thkim 검증됨
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.ParseException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.factory.GeoTools;
|
||||
import org.geotools.metadata.iso.citation.CitationImpl;
|
||||
import org.geotools.metadata.iso.citation.Citations;
|
||||
import org.geotools.referencing.NamedIdentifier;
|
||||
import org.geotools.referencing.factory.DirectAuthorityFactory;
|
||||
import org.geotools.referencing.factory.ReferencingFactoryContainer;
|
||||
import org.geotools.referencing.wkt.Symbols;
|
||||
import org.geotools.util.SimpleInternationalString;
|
||||
import org.opengis.metadata.Identifier;
|
||||
import org.opengis.metadata.citation.Citation;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.IdentifiedObject;
|
||||
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||
import org.opengis.referencing.crs.CRSAuthorityFactory;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.util.InternationalString;
|
||||
|
||||
public class O2CRSOverrideFactory
|
||||
extends DirectAuthorityFactory
|
||||
implements CRSAuthorityFactory {
|
||||
private CitationImpl authority = new CitationImpl((CharSequence)"O2CRS Override");
|
||||
private final String o2crsFileName = "o2crs.properties";
|
||||
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
||||
private final Parser parser = new Parser();
|
||||
|
||||
public O2CRSOverrideFactory() {
|
||||
super(ReferencingFactoryContainer.instance(null), 100);
|
||||
try {
|
||||
this.initCrsDefinitions();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException {
|
||||
HashSet<String> codes = new HashSet<String>();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
codes.addAll(this.definitions.keySet());
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
public InternationalString getDescriptionText(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||
CoordinateReferenceSystem crs = this.createCoordinateReferenceSystem(code);
|
||||
return new SimpleInternationalString(crs.toWKT());
|
||||
}
|
||||
|
||||
public Citation getAuthority() {
|
||||
return this.authority;
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||
if (ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("CRS code is NULL.");
|
||||
}
|
||||
String[] codes = code.trim().toUpperCase().split(":");
|
||||
if (codes.length == 2) {
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
String[] keyCodes = key.split(":");
|
||||
if (!keyCodes[0].equalsIgnoreCase(codes[0].trim()) || !keyCodes[1].equalsIgnoreCase(codes[1].trim())) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
} else if (codes.length == 1) {
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
String[] keyCodes = key.split(":");
|
||||
if (!keyCodes[1].equalsIgnoreCase(codes[0].trim())) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
} else {
|
||||
throw new NoSuchAuthorityCodeException("CRS code has problem : " + code, code, code);
|
||||
}
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code : " + code, codes[0], codes[0]);
|
||||
}
|
||||
|
||||
public void initCrsDefinitions() throws Exception {
|
||||
try {
|
||||
File file = ServerUtil.findFile((File)ServerContext.getConfFolder(), (String)"o2crs.properties");
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Properties properties = ServerUtil.getPropertiesFromFile((File)file, (String)"=");
|
||||
Enumeration<Object> keys = properties.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String pKey = (String)keys.nextElement();
|
||||
try {
|
||||
String[] codes = pKey.trim().toUpperCase().split(":");
|
||||
if (codes.length != 2 || ServerUtil.isNullString((String)codes[0]) || ServerUtil.isNullString((String)codes[1])) {
|
||||
throw new FactoryException("Parameter [Authority:Code] has problem.");
|
||||
}
|
||||
codes[0] = codes[0].trim().toUpperCase();
|
||||
codes[1] = codes[1].trim().toUpperCase();
|
||||
if (this.isContainCRS(codes[0], codes[1])) {
|
||||
throw new FactoryException("CODE [" + codes[0] + ":" + codes[1] + "] is already exist.");
|
||||
}
|
||||
CoordinateReferenceSystem crs = this.parseWKT(codes[0], codes[1], properties.getProperty(pKey));
|
||||
if (crs == null) continue;
|
||||
pKey = String.valueOf(codes[0]) + ":" + codes[1];
|
||||
this.definitions.put(pKey, crs);
|
||||
this.addAuthority(codes[0]);
|
||||
LogMngr.getInstance().logInfo("[CRS]", "Success to add Override CRS [" + pKey + "] :: " + crs.toWKT());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Fail to add Override CRS [" + pKey + "] :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Can't access O2CRS Configuration File :: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
GeoTools.fireConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)wkt)) {
|
||||
throw new FactoryException("CRS WKT is NULL.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
Parser parser = this.parser;
|
||||
synchronized (parser) {
|
||||
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAuthority(String auth) {
|
||||
Citation cit = Citations.fromName((String)auth);
|
||||
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
||||
}
|
||||
|
||||
public boolean isContainAuthority(String auth) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
throw new FactoryException("AUTHORITY is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
for (Identifier identifier : this.authority.getIdentifiers()) {
|
||||
if (!identifier.getCode().equalsIgnoreCase(auth)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public boolean isContainCRS(String auth, String code) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
throw new FactoryException("AUTHORITY is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
if (ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("CODE is Null.");
|
||||
}
|
||||
code = code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
String key;
|
||||
String[] codes;
|
||||
Enumeration<String> keys = this.definitions.keys();
|
||||
do {
|
||||
if (keys.hasMoreElements()) continue;
|
||||
return false;
|
||||
} while (!(codes = (key = keys.nextElement()).split(":"))[0].equalsIgnoreCase(auth) || !codes[1].equalsIgnoreCase(code));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void insertCRS(String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||
if (this.isContainCRS(auth, code)) {
|
||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||
}
|
||||
if (crs == null) {
|
||||
throw new FactoryException("CRS is Null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
this.definitions.put(String.valueOf(auth) + ":" + code, crs);
|
||||
this.addAuthority(auth);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
if (write) {
|
||||
this.writeDefinitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void updateCRS(String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||
if (!this.isContainCRS(auth, code)) {
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code ", auth, code);
|
||||
}
|
||||
if (crs == null) {
|
||||
throw new FactoryException("CRS value is Null.");
|
||||
}
|
||||
String upKey = String.valueOf(auth.trim().toUpperCase()) + ":" + code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
this.definitions.put(upKey, crs);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
if (write) {
|
||||
this.writeDefinitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void removeCRS(String auth, String code, boolean write) throws Exception {
|
||||
if (!this.isContainCRS(auth, code)) {
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code ", auth, code);
|
||||
}
|
||||
String rmKey = String.valueOf(auth.trim().toUpperCase()) + ":" + code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
this.definitions.remove(rmKey);
|
||||
GeoTools.fireConfigurationChanged();
|
||||
if (write) {
|
||||
this.writeDefinitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public CoordinateReferenceSystem getCRS(String auth, String code) throws Exception {
|
||||
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
code = code.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
Enumeration<String> keys = this.definitions.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
String[] codes = key.split(":");
|
||||
if (!codes[0].equalsIgnoreCase(auth) || !codes[1].equalsIgnoreCase(code)) continue;
|
||||
return this.definitions.get(key);
|
||||
}
|
||||
}
|
||||
throw new NoSuchAuthorityCodeException("Not exists authority or code", auth, code);
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public Set<String> getAuthorityCodes(String auth) {
|
||||
TreeSet<String> codes = new TreeSet<String>();
|
||||
if (ServerUtil.isNullString((String)auth)) {
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
codes.addAll(this.definitions.keySet());
|
||||
}
|
||||
}
|
||||
auth = auth.trim().toUpperCase();
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
for (String key : this.definitions.keySet()) {
|
||||
String[] tempKeys = key.split(":");
|
||||
if (!tempKeys[0].equalsIgnoreCase(auth)) continue;
|
||||
codes.add(key);
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
private void writeDefinitions() {
|
||||
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||
synchronized (concurrentHashMap) {
|
||||
block28: {
|
||||
OutputStreamWriter writer = null;
|
||||
BufferedWriter bWriter = null;
|
||||
try {
|
||||
try {
|
||||
File crsFile = new File(ServerContext.getConfFolder(), "o2crs.properties");
|
||||
if (!crsFile.exists()) {
|
||||
crsFile.createNewFile();
|
||||
}
|
||||
crsFile.setExecutable(true, false);
|
||||
crsFile.setReadable(true);
|
||||
crsFile.setWritable(true);
|
||||
writer = new FileWriter(crsFile, false);
|
||||
bWriter = new BufferedWriter(writer);
|
||||
bWriter.append("# Additional CRS Definitions.").append("\n");
|
||||
bWriter.append("# ").append("\n");
|
||||
bWriter.append("# $AUTHORITY$ : CRS AUTHORITY").append("\n");
|
||||
bWriter.append("# $CODE$ : CRS CODE").append("\n");
|
||||
bWriter.append("# $WKT$ : CRS WKT").append("\n");
|
||||
bWriter.append("# ").append("\n");
|
||||
bWriter.append("# USE -> $AUTHORITY$:$CODE$=$WKT$").append("\n");
|
||||
bWriter.append("").append("\n");
|
||||
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||
for (String key : keys) {
|
||||
bWriter.append(key).append("=");
|
||||
bWriter.append(this.definitions.get(key).toWKT()).append("\n");
|
||||
}
|
||||
bWriter.flush();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CRS]", "Can't access O2CRS Configuration File :: " + e.getMessage());
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
if (bWriter != null) {
|
||||
try {
|
||||
bWriter.close();
|
||||
}
|
||||
catch (IOException iOException) {}
|
||||
}
|
||||
break block28;
|
||||
}
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
if (bWriter != null) {
|
||||
try {
|
||||
bWriter.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
throw throwable;
|
||||
}
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
if (bWriter != null) {
|
||||
try {
|
||||
bWriter.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class Parser
|
||||
extends org.geotools.referencing.wkt.Parser {
|
||||
private static final long serialVersionUID = -5910561042299146066L;
|
||||
private CitationImpl auth;
|
||||
private String code;
|
||||
|
||||
public Parser() {
|
||||
super(Symbols.DEFAULT, O2CRSOverrideFactory.this.factories);
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt) throws ParseException {
|
||||
this.auth = new CitationImpl(Citations.fromName((String)auth));
|
||||
this.code = code;
|
||||
return super.parseCoordinateReferenceSystem(wkt);
|
||||
}
|
||||
|
||||
protected Map<String, Object> alterProperties(Map<String, Object> properties) {
|
||||
properties.put("identifiers", new NamedIdentifier((Citation)this.auth, this.code));
|
||||
return super.alterProperties(properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.geotools.data.DataAccessFactory;
|
||||
import org.geotools.data.DataAccessFactory.Param;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.JDBCDataStoreFactory;
|
||||
import org.geotools.jdbc.SQLDialect;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.geotools.data.DataAccessFactory;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.JDBCDataStoreFactory;
|
||||
import org.geotools.jdbc.PrimaryKeyFinder;
|
||||
import org.geotools.jdbc.SQLDialect;
|
||||
|
||||
public class O2DSFactory
|
||||
extends JDBCDataStoreFactory {
|
||||
public static final DataAccessFactory.Param O2_SERVER_NAME = new DataAccessFactory.Param("o2map dbms server name", String.class, "DBMS server name(alias)", true);
|
||||
public static final DataAccessFactory.Param O2_PK_COLUMN_NAME = new DataAccessFactory.Param("o2map pk column name", String.class, "Primary key column name (default is GID)", true);
|
||||
public static final DataAccessFactory.Param O2_USE_SPATIAL = new DataAccessFactory.Param("o2map use spatial datatype for dbms", Boolean.class, "Condition for use spatial datatype", true);
|
||||
private final String sqlFileName = "/o2jdbcsql.properties";
|
||||
private HashMap<String, Object> dsParams = new HashMap();
|
||||
private SimpleSql dsSQL;
|
||||
|
||||
public O2DSFactory(HashMap params) throws Exception {
|
||||
this.dsParams = params;
|
||||
this.refindParameter();
|
||||
this.createDSSql();
|
||||
}
|
||||
|
||||
private void refindParameter() throws Exception {
|
||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||
if (dbType == null) {
|
||||
LogMngr.getInstance().logError("[DB]", "DBMS Type is Null");
|
||||
throw new NullPointerException("DBMS Type is Null");
|
||||
}
|
||||
if (DBMSType.class.getField(dbType.toUpperCase()) == null) {
|
||||
LogMngr.getInstance().logError("[DB]", "Not supportd DBMS Type :: " + dbType);
|
||||
throw new NullPointerException("Not supportd DBMS Type :: " + dbType);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDSSql() throws IOException, URISyntaxException {
|
||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
||||
return;
|
||||
}
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
File sqlFile = new File(ServerContext.getConfFolder(), "/o2jdbcsql.properties");
|
||||
FileInputStream in = new FileInputStream(sqlFile);
|
||||
prop.load(in);
|
||||
((InputStream)in).close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Can't access Spatial Query file :: " + e.getMessage());
|
||||
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
||||
LogMngr.getInstance().logError("[DB]", "Now use default");
|
||||
InputStream in = ServerContext.class.getResourceAsStream("/o2jdbcsql.properties");
|
||||
prop.load(in);
|
||||
in.close();
|
||||
}
|
||||
Boolean useSpatial = (Boolean)O2_USE_SPATIAL.lookUp(this.dsParams);
|
||||
if (useSpatial.booleanValue()) {
|
||||
this.dsSQL = new SimpleSql(dbType);
|
||||
this.dsSQL.setSqlEnvelope(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".spatial.envelope"));
|
||||
this.dsSQL.setSqlBBox(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".spatial.bbox"));
|
||||
this.dsSQL.setGeomToWKB(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".geometry.to.wkb"));
|
||||
this.dsSQL.setGeomFromWKB(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".geometry.from.wkb"));
|
||||
if (this.dsSQL.isValidate()) {
|
||||
LogMngr.getInstance().logDebug("[DB]", "Crate Spatial Query :: " + this.dsSQL.toString());
|
||||
} else {
|
||||
this.dsSQL = null;
|
||||
LogMngr.getInstance().logError("[DB]", "Spatial Query not avilable :: " + dbType);
|
||||
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
||||
throw new IOException("Spatial Query not avilable :: " + dbType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JDBCDataStore getDataStore() throws IOException {
|
||||
return this.createDataStore(this.dsParams);
|
||||
}
|
||||
|
||||
protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params) throws IOException {
|
||||
try {
|
||||
String keyColumn = (String)O2_PK_COLUMN_NAME.lookUp(this.dsParams);
|
||||
dataStore.setPrimaryKeyFinder((PrimaryKeyFinder)new O2DSPrimaryKeyFinder(keyColumn));
|
||||
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: " + keyColumn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
dataStore.setPrimaryKeyFinder((PrimaryKeyFinder)new O2DSPrimaryKeyFinder("GID"));
|
||||
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: GID");
|
||||
}
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
public BasicDataSource createDataSource(Map params) throws IOException {
|
||||
Boolean validate;
|
||||
Integer maxWait;
|
||||
Integer maxConn;
|
||||
Integer minConn;
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
dataSource.setDriverClassName(this.getDriverClassName());
|
||||
dataSource.setUrl(this.getJDBCUrl(params));
|
||||
String user = (String)USER.lookUp(params);
|
||||
dataSource.setUsername(user);
|
||||
String passwd = (String)PASSWD.lookUp(params);
|
||||
if (passwd != null) {
|
||||
dataSource.setPassword(passwd);
|
||||
}
|
||||
if ((minConn = (Integer)MINCONN.lookUp(params)) != null) {
|
||||
dataSource.setMinIdle(minConn.intValue());
|
||||
}
|
||||
if ((maxConn = (Integer)MAXCONN.lookUp(params)) != null) {
|
||||
dataSource.setMaxActive(maxConn.intValue());
|
||||
}
|
||||
if ((maxWait = (Integer)MAXWAIT.lookUp(params)) != null && maxWait != -1) {
|
||||
dataSource.setMaxWait((long)(maxWait * 1000));
|
||||
}
|
||||
if ((validate = (Boolean)VALIDATECONN.lookUp(params)) != null && validate.booleanValue() && this.getValidationQuery() != null) {
|
||||
dataSource.setTestOnBorrow(true);
|
||||
dataSource.setValidationQuery(this.getValidationQuery());
|
||||
}
|
||||
dataSource.setAccessToUnderlyingConnectionAllowed(true);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
protected SQLDialect createSQLDialect(JDBCDataStore dataStore) {
|
||||
boolean useSpatial = true;
|
||||
try {
|
||||
useSpatial = (Boolean)O2_USE_SPATIAL.lookUp(this.dsParams);
|
||||
if (useSpatial) {
|
||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
||||
return new OracleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore);
|
||||
}
|
||||
return new SimpleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore, this.dsSQL);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Fail :: To Make UseSpatial SQLDialect :: " + e.getMessage());
|
||||
}
|
||||
LogMngr.getInstance().logError("[DB]", "Now Use Non-Spatial SQLDialect.");
|
||||
try {
|
||||
return new NonSpatialDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), (String)DBTYPE.lookUp(this.dsParams), dataStore);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Fail :: To Make Non-Spatial SQLDialect :: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getDriverClassName() {
|
||||
try {
|
||||
return ConnMngr.getInstance().getConnObj(this.getDatabaseID()).getDriverClassName();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getDatabaseID() {
|
||||
try {
|
||||
return (String)DBTYPE.lookUp(this.dsParams);
|
||||
}
|
||||
catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.getDescription();
|
||||
}
|
||||
|
||||
protected String getJDBCUrl(Map params) throws IOException {
|
||||
try {
|
||||
return ConnMngr.getInstance().getConnObj(this.getDatabaseID()).getJDBCUrl((String)HOST.lookUp(this.dsParams), (Integer)PORT.lookUp(this.dsParams), (String)DATABASE.lookUp(this.dsParams));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
try {
|
||||
return (String)DBTYPE.lookUp(this.dsParams);
|
||||
}
|
||||
catch (IOException e) {
|
||||
return "JDBC DATASTORE";
|
||||
}
|
||||
}
|
||||
|
||||
protected String getValidationQuery() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static enum DBMSType {
|
||||
ORACLE("ORACLE"),
|
||||
POSTGIS("POSTGIS"),
|
||||
MYSQL("MYSQL"),
|
||||
TIBERO("TIBERO"),
|
||||
ALTIBASE("ALTIBASE"),
|
||||
KAIROS("KAIROS");
|
||||
|
||||
private String type;
|
||||
|
||||
private DBMSType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getTypeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.collection.SpatialIndexFeatureCollection;
|
||||
import org.geotools.data.collection.SpatialIndexFeatureSource;
|
||||
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||
import org.geotools.data.shapefile.ShpDataStore;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.data.store.ContentDataStore;
|
||||
import org.geotools.data.store.ContentDataStoreRefinder;
|
||||
import org.geotools.data.store.ContentFeatureSource;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.jdbc.JDBCFeatureStore;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.Id;
|
||||
import org.opengis.filter.identity.GmlObjectId;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class O2DSMngr {
|
||||
private static HashMap<String, SpatialIndexFeatureSource> memoryStore = new HashMap<String, SpatialIndexFeatureSource>();
|
||||
|
||||
public static void putMemoryFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, Filter filter) throws Exception {
|
||||
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + tableName;
|
||||
key = key.toUpperCase();
|
||||
SpatialIndexFeatureSource featureSource = memoryStore.get(key);
|
||||
if (featureSource != null)
|
||||
throw new IOException("Memory store [" + key + "] is already exist.");
|
||||
O2SpatialIndexFeatureCollection collection =
|
||||
new O2SpatialIndexFeatureCollection(
|
||||
getFeatureSource(layerType, serverName, tableName).getFeatures(filter));
|
||||
featureSource = new SpatialIndexFeatureSource((SpatialIndexFeatureCollection)collection);
|
||||
memoryStore.put(key, featureSource);
|
||||
}
|
||||
|
||||
public static void clearMemoryStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws IOException {
|
||||
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + tableName;
|
||||
key = key.toUpperCase();
|
||||
synchronized (memoryStore) {
|
||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||
if (featureSource == null)
|
||||
throw new IOException("Memory store [" + key + "] is not exist.");
|
||||
((SpatialIndexFeatureCollection)featureSource.getFeatures()).clear();
|
||||
featureSource = null;
|
||||
memoryStore.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearMemoryStore() throws IOException {
|
||||
synchronized (memoryStore) {
|
||||
for (SimpleFeatureSource featureSource : memoryStore.values())
|
||||
featureSource = null;
|
||||
memoryStore.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static JDBCFeatureStore getFeatureStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws Exception {
|
||||
JDBCFeatureStore featureStore;
|
||||
if (layerType == null)
|
||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||
if (ServerUtil.isNullString(serverName))
|
||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||
if (ServerUtil.isNullString(tableName))
|
||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||
if (layerType != LayerFactory.LayerType.JDBC)
|
||||
throw new Exception("DataStore type [" + layerType + "] is not support Transaction");
|
||||
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
||||
if (featureSource instanceof SpatialIndexFeatureSource)
|
||||
throw new Exception("Memory DataStore is not support Transaction");
|
||||
if (featureSource instanceof JDBCFeatureStore) {
|
||||
featureStore = (JDBCFeatureStore)featureSource;
|
||||
} else {
|
||||
featureStore = new JDBCFeatureStore(((ContentFeatureSource)featureSource).getEntry(), null);
|
||||
}
|
||||
return featureStore;
|
||||
}
|
||||
|
||||
public static SimpleFeatureSource getFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName) throws Exception {
|
||||
if (layerType == null)
|
||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||
if (ServerUtil.isNullString(serverName))
|
||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||
serverName = serverName.trim().toUpperCase();
|
||||
if (ServerUtil.isNullString(tableName))
|
||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||
tableName = tableName.trim().toUpperCase();
|
||||
try {
|
||||
String key = String.valueOf(layerType.getType()) + "_" + serverName + "_" + tableName;
|
||||
key = key.toUpperCase();
|
||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||
if (featureSource != null)
|
||||
return featureSource;
|
||||
} catch (Exception exception) {}
|
||||
if (layerType == LayerFactory.LayerType.JDBC)
|
||||
try {
|
||||
return (SimpleFeatureSource)JdbcStoreMngr.getDataStore(serverName).getFeatureSource(tableName);
|
||||
} catch (IOException e) {
|
||||
return (SimpleFeatureSource)ContentDataStoreRefinder.refindJDBCFeatureSource((ContentDataStore)JdbcStoreMngr.getDataStore(serverName), tableName.toLowerCase());
|
||||
}
|
||||
if (layerType == LayerFactory.LayerType.GEOWAVE) {
|
||||
GeoWaveDataStore store = GWaveStoreMngr.getDataStore(serverName);
|
||||
if (store == null)
|
||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||
}
|
||||
if (layerType == LayerFactory.LayerType.SHAPE) {
|
||||
ShpDataStore store = ShpStoreMngr.getDataStore(tableName);
|
||||
if (store == null)
|
||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||
}
|
||||
if (layerType == LayerFactory.LayerType.O2WPSVEC) {
|
||||
ContentDataStore store = WpsVecStoreMngr.getShpDataStore(tableName);
|
||||
if (store == null)
|
||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||
}
|
||||
throw new Exception("DataStore type [" + layerType + "] is not support");
|
||||
}
|
||||
|
||||
public static SimpleFeatureSource changeCRSFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, CoordinateReferenceSystem crs) throws Exception {
|
||||
if (ServerUtil.isNullString(tableName))
|
||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
||||
if (featureSource.getDataStore() instanceof ShapefileDataStore) {
|
||||
ShapefileDataStore shapeStore = (ShapefileDataStore)featureSource.getDataStore();
|
||||
shapeStore.forceSchemaCRS(crs);
|
||||
}
|
||||
return ContentDataStoreRefinder.changeCRSFeatureSource(featureSource, crs);
|
||||
}
|
||||
|
||||
public static void disposeStores() {
|
||||
JdbcStoreMngr.disposeDataStores();
|
||||
GWaveStoreMngr.disposeDataStores();
|
||||
ShpStoreMngr.disposeDataStores();
|
||||
WpsVecStoreMngr.disposeDataStores();
|
||||
for (SimpleFeatureSource source : memoryStore.values())
|
||||
source = null;
|
||||
memoryStore.clear();
|
||||
}
|
||||
|
||||
public static void disposeStore(String key) {
|
||||
JdbcStoreMngr.disposeDataStore(key);
|
||||
GWaveStoreMngr.disposeDataStore(key);
|
||||
ShpStoreMngr.disposeDataStore(key);
|
||||
WpsVecStoreMngr.disposeDataStore(key);
|
||||
SimpleFeatureSource source = (SimpleFeatureSource)memoryStore.remove(key);
|
||||
source = null;
|
||||
}
|
||||
|
||||
public static SimpleFeature getGmlObject(LayerFactory.LayerType layerType, String serverName, GmlObjectId id, Hints hints) throws Exception {
|
||||
if (layerType == null)
|
||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||
if (ServerUtil.isNullString(serverName))
|
||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||
if (id == null)
|
||||
throw new IllegalArgumentException("Parameter GmlObjectId is NULL.");
|
||||
try {
|
||||
String typeName = id.getID().substring(0, id.getID().lastIndexOf("."));
|
||||
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + typeName;
|
||||
key = key.toUpperCase();
|
||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||
if (featureSource != null)
|
||||
return getMemoryGmlObject(featureSource, id, hints);
|
||||
} catch (Exception exception) {}
|
||||
if (layerType == LayerFactory.LayerType.JDBC)
|
||||
return (SimpleFeature)JdbcStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
||||
if (layerType == LayerFactory.LayerType.GEOWAVE)
|
||||
return (SimpleFeature)GWaveStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
||||
if (layerType == LayerFactory.LayerType.SHAPE)
|
||||
return (SimpleFeature)ShpStoreMngr.getGmlObject(id, hints);
|
||||
if (layerType == LayerFactory.LayerType.O2WPSVEC)
|
||||
return (SimpleFeature)WpsVecStoreMngr.getGmlObject(id, hints);
|
||||
throw new Exception("DataStore type [" + layerType + "] is not support");
|
||||
}
|
||||
|
||||
public static SimpleFeature getMemoryGmlObject(SimpleFeatureSource featureSource, GmlObjectId id, Hints hints) throws Exception {
|
||||
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||
Query query = new Query();
|
||||
query.setFilter((Filter)filter);
|
||||
query.setHints(hints);
|
||||
SimpleFeatureCollection features = featureSource.getFeatures(query);
|
||||
if (!features.isEmpty()) {
|
||||
SimpleFeatureIterator fi = features.features();
|
||||
try {
|
||||
if (fi.hasNext())
|
||||
return (SimpleFeature)fi.next();
|
||||
} finally {
|
||||
fi.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.geotools.jdbc.AutoGeneratedPrimaryKeyColumn;
|
||||
import org.geotools.jdbc.ColumnMetadata;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.NonIncrementingPrimaryKeyColumn;
|
||||
import org.geotools.jdbc.PrimaryKey;
|
||||
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||
import org.geotools.jdbc.PrimaryKeyFinder;
|
||||
import org.geotools.jdbc.SQLDialect;
|
||||
import org.geotools.jdbc.SequencedPrimaryKeyColumn;
|
||||
import org.geotools.util.logging.Logging;
|
||||
|
||||
public class O2DSPrimaryKeyFinder extends PrimaryKeyFinder
|
||||
{
|
||||
protected static final Logger LOGGER = Logging.getLogger(O2DSPrimaryKeyFinder.class);
|
||||
private String primaryKeyColumn = "GID";
|
||||
|
||||
public O2DSPrimaryKeyFinder(String keyColumn) {
|
||||
this.primaryKeyColumn = keyColumn.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public PrimaryKey getPrimaryKey(JDBCDataStore store, String databaseSchema, String tableName, Connection cx)
|
||||
throws SQLException
|
||||
{
|
||||
ColumnMetadata meta = getPKColumnMetadata(store, tableName, cx);
|
||||
if (meta != null) {
|
||||
return createPrimaryKey(store, cx, tableName, meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
ColumnMetadata getPKColumnMetadata(JDBCDataStore store, String tableName, Connection cx)
|
||||
throws SQLException
|
||||
{
|
||||
String userName = cx.getMetaData().getUserName().toUpperCase();
|
||||
|
||||
DatabaseMetaData metaData = cx.getMetaData();
|
||||
ResultSet columns = metaData.getColumns(cx.getCatalog(), store.getDatabaseSchema(), tableName, "%");
|
||||
if (store.getFetchSize() > 0) {
|
||||
columns.setFetchSize(store.getFetchSize());
|
||||
}
|
||||
try
|
||||
{
|
||||
while (columns.next())
|
||||
{
|
||||
String schemaName = columns.getString("TABLE_SCHEM");
|
||||
if ((store.getSQLDialect() instanceof O2SqlDialect)) {
|
||||
String dbType = ((O2SqlDialect)store.getSQLDialect()).getDbType();
|
||||
|
||||
if (dbType.equalsIgnoreCase(O2DSFactory.DBMSType.POSTGIS.getTypeName()))
|
||||
{
|
||||
schemaName = "public";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((schemaName != null) &&
|
||||
(schemaName.trim().length() != 0) &&
|
||||
(!schemaName.equalsIgnoreCase(userName)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((schemaName != null) && (schemaName.trim().length() != 0) && (
|
||||
(store.getDatabaseSchema() == null) || (store.getDatabaseSchema().trim().length() == 0))) {
|
||||
store.setDatabaseSchema(schemaName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.primaryKeyColumn.equalsIgnoreCase(columns.getString("COLUMN_NAME")))
|
||||
{
|
||||
ColumnMetadata column = new ColumnMetadata();
|
||||
column.setName(columns.getString("COLUMN_NAME"));
|
||||
column.setTypeName(columns.getString("TYPE_NAME"));
|
||||
column.setSqlType(columns.getInt("DATA_TYPE"));
|
||||
column.setNullable("YES".equalsIgnoreCase(columns.getString("IS_NULLABLE")));
|
||||
|
||||
Class binding = store.getSQLDialect().getMapping(columns, cx);
|
||||
if (binding == null)
|
||||
{
|
||||
binding = store.getMapping(column.getTypeName());
|
||||
if (binding == null) {
|
||||
binding = store.getMapping(column.getSqlType());
|
||||
}
|
||||
}
|
||||
column.setBinding(binding);
|
||||
|
||||
return column;
|
||||
}
|
||||
}
|
||||
} finally { store.closeSafe(columns); } store.closeSafe(columns);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
PrimaryKey createPrimaryKey(JDBCDataStore store, Connection cx, String tableName, ColumnMetadata columnMeta)
|
||||
throws SQLException
|
||||
{
|
||||
LogMngr.getInstance().logDebug("[DB]", "Create primary key for [" + tableName + "]");
|
||||
|
||||
ArrayList cols = new ArrayList();
|
||||
|
||||
PrimaryKeyColumn col = null;
|
||||
|
||||
Statement st = cx.createStatement();
|
||||
try
|
||||
{
|
||||
st.setFetchSize(1);
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT ");
|
||||
store.getSQLDialect().encodeColumnName(null, columnMeta.getName(), sql);
|
||||
sql.append(" FROM ");
|
||||
if ((store.getDatabaseSchema() != null) && (!store.getDatabaseSchema().equals(""))) {
|
||||
store.getSQLDialect().encodeSchemaName(store.getDatabaseSchema(), sql);
|
||||
sql.append(".");
|
||||
}
|
||||
store.getSQLDialect().encodeTableName(tableName, sql);
|
||||
|
||||
sql.append(" WHERE 0=1");
|
||||
|
||||
LOGGER.log(Level.FINE, "Grabbing table pk metadata: {0}", sql);
|
||||
|
||||
ResultSet rs = st.executeQuery(sql.toString());
|
||||
try
|
||||
{
|
||||
if (rs.getMetaData().isAutoIncrement(1))
|
||||
col = new AutoGeneratedPrimaryKeyColumn(columnMeta.getName(), columnMeta.getBinding());
|
||||
}
|
||||
finally {
|
||||
store.closeSafe(rs);
|
||||
}
|
||||
} finally {
|
||||
store.closeSafe(st);
|
||||
}
|
||||
|
||||
if (col == null) {
|
||||
try {
|
||||
String sequenceName = store.getSQLDialect().getSequenceForColumn(store.getDatabaseSchema(), tableName, columnMeta.getName(), cx);
|
||||
if (sequenceName != null)
|
||||
col = new SequencedPrimaryKeyColumn(columnMeta.getName(), columnMeta.getBinding(), sequenceName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Error occured determining sequence for " + columnMeta.getName() + ", " + tableName, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (col == null) {
|
||||
col = new NonIncrementingPrimaryKeyColumn(columnMeta.getName(), columnMeta.getBinding());
|
||||
}
|
||||
|
||||
cols.add(col);
|
||||
|
||||
if (!cols.isEmpty()) {
|
||||
return new PrimaryKey(tableName, cols);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.StyledLayerDescriptorImpl;
|
||||
import org.geotools.styling.UserLayer;
|
||||
|
||||
public class O2DemLayer extends Layer
|
||||
{
|
||||
final O2LayerLevelSet levelSet;
|
||||
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap();
|
||||
private Style currentStyle;
|
||||
|
||||
public O2DemLayer(AVList params)
|
||||
throws Exception
|
||||
{
|
||||
super(params);
|
||||
try
|
||||
{
|
||||
this.levelSet = ((O2LayerLevelSet)params.getValue("o2layer.conf.level.set"));
|
||||
|
||||
if ((this.levelSet == null) || (this.levelSet.size() == 0))
|
||||
throw new IOException("LevelSet has no level");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("O2Layer levelset is not available. :: " + e);
|
||||
}
|
||||
|
||||
Style style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
setCurrentStyle(style);
|
||||
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||
|
||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
||||
if (sld != null) {
|
||||
initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Style From SLD FILE :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public O2LayerLevelSet getLevelSet()
|
||||
{
|
||||
return this.levelSet;
|
||||
}
|
||||
|
||||
public String getSourceName()
|
||||
{
|
||||
return this.levelSet.getRootPath().getAbsolutePath();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox()
|
||||
{
|
||||
return new ReferencedEnvelope(this.levelSet.getBBox(), getCRS());
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write)
|
||||
{
|
||||
Style defaultStyle = null;
|
||||
ConcurrentHashMap tempStore = new ConcurrentHashMap();
|
||||
|
||||
ExtractRasterStyleVisitor sVisitor = new ExtractRasterStyleVisitor();
|
||||
|
||||
sld.accept(sVisitor);
|
||||
sld = (StyledLayerDescriptorImpl)sVisitor.getCopy();
|
||||
|
||||
Iterator iterLayer = sld.layers().iterator();
|
||||
Iterator iterStyle;
|
||||
label259: for (; iterLayer.hasNext();
|
||||
iterStyle.hasNext())
|
||||
{
|
||||
StyledLayer styledLayer = (StyledLayer)iterLayer.next();
|
||||
|
||||
if ((!ServerUtil.isNullString(styledLayer.getName())) &&
|
||||
(!styledLayer.getName().equalsIgnoreCase(getName())))
|
||||
{
|
||||
break label259;
|
||||
}
|
||||
|
||||
iterStyle = getStyleIterator(styledLayer);
|
||||
//continue;
|
||||
Style style = (Style)iterStyle.next();
|
||||
|
||||
if (!(style instanceof NamedStyle))
|
||||
{
|
||||
if (ServerUtil.isNullString(style.getName()))
|
||||
style.setName(getName());
|
||||
else {
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
}
|
||||
|
||||
tempStore.put(style.getName(), style);
|
||||
if ((defaultStyle != null) &&
|
||||
(defaultStyle.getName().equals(style.getName()))) {
|
||||
defaultStyle = null;
|
||||
}
|
||||
|
||||
if (style.isDefault())
|
||||
{
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
} else {
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (defaultStyle == null)
|
||||
{
|
||||
if (getCurrentStyle() == null)
|
||||
{
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
} else {
|
||||
defaultStyle = (Style)tempStore.get(getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = (Style)tempStore.values().iterator().next();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultStyle = (Style)tempStore.get(getCurrentStyle().getName());
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = getCurrentStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentStyle(defaultStyle);
|
||||
|
||||
this.styleStore.putAll(tempStore);
|
||||
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD100(getStyleSLD());
|
||||
}
|
||||
|
||||
public synchronized void reloadServiceStyle()
|
||||
{
|
||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
||||
if (sld != null) {
|
||||
initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Reload Style From SLD FILE :: [Map:" + getMapName() + "/Layer:" + getName() + "]");
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + getMapName() + "/Layer:" + getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public Style getRenderStyle(String styleName)
|
||||
{
|
||||
Style style = getStyle(styleName);
|
||||
if (style == null) {
|
||||
style = getCurrentStyle();
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
public Style getStyle(String styleName)
|
||||
{
|
||||
if (!ServerUtil.isNullString(styleName)) {
|
||||
return (Style)this.styleStore.get(styleName.trim().toUpperCase());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Style getCurrentStyle()
|
||||
{
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
private Style setCurrentStyle(Style style)
|
||||
{
|
||||
if (this.currentStyle != null) {
|
||||
this.currentStyle.setDefault(false);
|
||||
}
|
||||
|
||||
this.currentStyle = style;
|
||||
this.currentStyle.setDefault(true);
|
||||
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
private Iterator<Style> getStyleIterator(StyledLayer layer)
|
||||
{
|
||||
if ((layer instanceof NamedLayer)) {
|
||||
return ((NamedLayer)layer).styles().iterator();
|
||||
}
|
||||
return ((UserLayer)layer).userStyles().iterator();
|
||||
}
|
||||
|
||||
public StyledLayerDescriptor getStyleSLD()
|
||||
{
|
||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||
layer.setName(getName());
|
||||
layer.styles().addAll(this.styleStore.values());
|
||||
|
||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||
sld.addStyledLayer(layer);
|
||||
sld.setName(getName());
|
||||
|
||||
return sld;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class O2DemLayerMngr {
|
||||
public static void initLayers() {
|
||||
try {
|
||||
File dir = ServerContext.getPluginsFolder();
|
||||
String fileName = String.valueOf(ServerContext.getMap().getName()) + LayerFactory.LayerType.O2DEM.getPrefix();
|
||||
File confFile = ServerUtil.findFile((File)dir, (String)fileName);
|
||||
if (confFile == null) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "Skip create O2DemLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||
return;
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[O2DEM]", "[" + confFile.getName() + "] Now create O2DemLayer from this configuration");
|
||||
ArrayList<O2LayerInfo> layerInfoList = O2DemLayerMngr.parseO2DemLayer(confFile);
|
||||
if (layerInfoList == null || layerInfoList.isEmpty()) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "[" + confFile.getName() + "] Fail to create O2DemLayer :: O2DemLayer size is ZERO[0] from this configuration");
|
||||
return;
|
||||
}
|
||||
for (O2LayerInfo info : layerInfoList) {
|
||||
LogMngr.getInstance().logDebug("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this O2DemLayer");
|
||||
try {
|
||||
O2DemLayerMngr.addLayer(info.getLayerPath(), info.getLayerName(), info.getLayerCRS(), info.getDesc(), info.getMinData(), info.getMaxData(), info.getNoData());
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " + "[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " + "[RefServer:" + LayerFactory.LayerType.O2IMG.getType() + "/RefSource:" + info.getLayerPath() + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[O2DEM]", "");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "Create O2DemLayer Fail :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<O2LayerInfo> parseO2DemLayer(File conf) {
|
||||
if (!conf.exists()) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] Create O2DemLayer Fail :: O2DemLayer configuration is not exist");
|
||||
return null;
|
||||
}
|
||||
ArrayList<O2LayerInfo> layerInfoList = new ArrayList<O2LayerInfo>();
|
||||
O2LayerInfo lInfo = null;
|
||||
BufferedReader bReader = null;
|
||||
try {
|
||||
try {
|
||||
String line;
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||
try {
|
||||
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||
lInfo = new O2LayerInfo();
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||
lInfo.setActivate(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||
lInfo.setLayerName(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.CRS")) {
|
||||
lInfo.setLayerCRS(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.PATH")) {
|
||||
lInfo.setLayerPath(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.DESC")) {
|
||||
lInfo.setDesc(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.DATA.MIN")) {
|
||||
lInfo.setMinData(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.DATA.MAX")) {
|
||||
lInfo.setMaxData(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.DATA.NODATA")) {
|
||||
lInfo.setNoData(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||
if (lInfo != null && lInfo.isAvailable()) {
|
||||
layerInfoList.add(lInfo);
|
||||
} else {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] Skip this O2DemLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||
}
|
||||
lInfo = null;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] O2DemLayer configuration file is not valid :: " + e.getMessage());
|
||||
try {
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
catch (IOException e2) {
|
||||
bReader = null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
return layerInfoList;
|
||||
}
|
||||
|
||||
public static O2DemLayer addLayer(File layerPath, String layerName, CoordinateReferenceSystem crs, String desc, Float min, Float max, Float noData) throws Exception {
|
||||
if (layerPath == null || !layerPath.exists() || layerPath.isFile()) {
|
||||
throw new IOException("O2DemLayer levelset is not exist [" + layerPath.getAbsolutePath() + "]");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)layerName)) {
|
||||
throw new IOException("O2DemLayer LayerName is null");
|
||||
}
|
||||
if (crs == null) {
|
||||
throw new IOException("O2DemLayer LayerCRS is null");
|
||||
}
|
||||
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet((LayerFactory.LayerType)LayerFactory.LayerType.O2DEM, (File)layerPath);
|
||||
if (min != null) {
|
||||
lvlSet.setMinData(min);
|
||||
}
|
||||
if (max != null) {
|
||||
lvlSet.setMaxData(max);
|
||||
}
|
||||
if (noData != null) {
|
||||
lvlSet.setNoData(noData);
|
||||
}
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||
params.setValue("conf.service.ref.server", (Object)LayerFactory.LayerType.O2DEM.getType());
|
||||
params.setValue("conf.service.ref.source", (Object)layerPath.getParent());
|
||||
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||
params.setValue("conf.service.sld", null);
|
||||
params.setValue("conf.service.use.cache", (Object)false);
|
||||
params.setValue("conf.service.last.update", null);
|
||||
params.setValue("conf.service.description", (Object)desc);
|
||||
params.setValue("o2layer.conf.level.set", (Object)lvlSet);
|
||||
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.O2DEM, (AVList)params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
return (O2DemLayer)layer;
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2DEM);
|
||||
try {
|
||||
O2DemLayerMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "Success to reload O2DemLayers.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2DEM]", "Fail to reload O2DemLayers. Now use previous O2DemLayers :: " + e);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
import java.io.IOException;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.collection.DelegateFeatureReader;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||
import org.geotools.feature.FeatureCollection;
|
||||
import org.geotools.feature.FeatureIterator;
|
||||
import org.geotools.feature.collection.DecoratingSimpleFeatureCollection;
|
||||
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||
import org.geotools.feature.visitor.FeatureAttributeVisitor;
|
||||
import org.geotools.filter.FilterAttributeExtractor;
|
||||
import org.opengis.feature.FeatureVisitor;
|
||||
import org.opengis.feature.IllegalAttributeException;
|
||||
import org.opengis.feature.Property;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.FeatureType;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.ExpressionVisitor;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
|
||||
public class O2FeatureCollection
|
||||
extends DecoratingSimpleFeatureCollection {
|
||||
SimpleFeatureType featureType;
|
||||
boolean isRetype = false;
|
||||
boolean isInitNullValue = false;
|
||||
|
||||
public O2FeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> delegate, SimpleFeatureType featureType) {
|
||||
this(DataUtilities.simple(delegate), featureType);
|
||||
}
|
||||
|
||||
public O2FeatureCollection(SimpleFeatureCollection delegate, SimpleFeatureType fType) {
|
||||
super(delegate);
|
||||
if (fType == null) {
|
||||
fType = (SimpleFeatureType)delegate.getSchema();
|
||||
} else {
|
||||
this.isRetype = true;
|
||||
}
|
||||
this.featureType = fType;
|
||||
}
|
||||
|
||||
public SimpleFeatureType getSchema() {
|
||||
return this.featureType;
|
||||
}
|
||||
|
||||
protected boolean canDelegate(FeatureVisitor visitor) {
|
||||
if (visitor instanceof FeatureAttributeVisitor) {
|
||||
FilterAttributeExtractor extractor = new FilterAttributeExtractor(this.featureType);
|
||||
for (Expression e : ((FeatureAttributeVisitor)visitor).getExpressions()) {
|
||||
e.accept((ExpressionVisitor)extractor, null);
|
||||
}
|
||||
for (PropertyName pname : extractor.getPropertyNameSet()) {
|
||||
AttributeDescriptor att = (AttributeDescriptor)pname.evaluate((Object)this.featureType);
|
||||
if (att != null) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FeatureReader<SimpleFeatureType, SimpleFeature> reader() throws IOException {
|
||||
return new DelegateFeatureReader((FeatureType)this.getSchema(), (FeatureIterator)this.features());
|
||||
}
|
||||
|
||||
public boolean isRetype() {
|
||||
return this.isRetype;
|
||||
}
|
||||
|
||||
public void setRetype(boolean bool) {
|
||||
this.isRetype = bool;
|
||||
}
|
||||
|
||||
public boolean isInitNullValue() {
|
||||
return this.isInitNullValue;
|
||||
}
|
||||
|
||||
public void setInitNullValue(boolean bool) {
|
||||
this.isInitNullValue = bool;
|
||||
}
|
||||
|
||||
public SimpleFeatureIterator features() {
|
||||
return new O2ReTypingFeatureIterator(this.delegate, this.getSchema(), this.isRetype(), this.isInitNullValue());
|
||||
}
|
||||
|
||||
protected AttributeDescriptor[] typeAttributes(SimpleFeatureType original, SimpleFeatureType target) {
|
||||
if (target.equals((Object)original)) {
|
||||
throw new IllegalArgumentException("FeatureReader allready produces contents with the correct schema");
|
||||
}
|
||||
if (target.getAttributeCount() > original.getAttributeCount()) {
|
||||
throw new IllegalArgumentException("Unable to retype FeatureReader<SimpleFeatureType, SimpleFeature> (origional does not cover requested type)");
|
||||
}
|
||||
AttributeDescriptor[] types = new AttributeDescriptor[target.getAttributeCount()];
|
||||
int i = 0;
|
||||
while (i < target.getAttributeCount()) {
|
||||
AttributeDescriptor attrib = target.getDescriptor(i);
|
||||
String xpath = attrib.getLocalName();
|
||||
types[i] = attrib;
|
||||
if (!attrib.equals(original.getDescriptor(xpath))) {
|
||||
throw new IllegalArgumentException("Unable to retype FeatureReader<SimpleFeatureType, SimpleFeature> (origional does not cover " + xpath + ")");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
class O2ReTypingFeatureIterator
|
||||
implements SimpleFeatureIterator {
|
||||
SimpleFeatureType source;
|
||||
AttributeDescriptor[] types;
|
||||
SimpleFeatureIterator delegate;
|
||||
SimpleFeatureType target;
|
||||
boolean retyping;
|
||||
boolean initNullValue = false;
|
||||
SimpleFeatureBuilder builder;
|
||||
|
||||
public O2ReTypingFeatureIterator(SimpleFeatureCollection featuresource, SimpleFeatureType target, boolean retype, boolean nullValue) {
|
||||
boolean test = featuresource.isEmpty();
|
||||
this.source = (SimpleFeatureType)featuresource.getSchema();
|
||||
this.target = target;
|
||||
this.delegate = featuresource.features();
|
||||
this.retyping = retype;
|
||||
this.initNullValue = nullValue;
|
||||
this.builder = new SimpleFeatureBuilder(target);
|
||||
}
|
||||
|
||||
public SimpleFeatureIterator getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this.delegate.hasNext();
|
||||
}
|
||||
|
||||
public SimpleFeature next() {
|
||||
SimpleFeature feature = (SimpleFeature)this.delegate.next();
|
||||
if (this.initNullValue) {
|
||||
for (Property property : feature.getValue()) {
|
||||
if (property.getValue() != null) continue;
|
||||
property.setValue((Object)"");
|
||||
}
|
||||
}
|
||||
if (!this.retyping) {
|
||||
return feature;
|
||||
}
|
||||
try {
|
||||
String fid = feature.getID();
|
||||
this.types = O2FeatureCollection.this.typeAttributes(this.source, this.target);
|
||||
int i = 0;
|
||||
while (i < this.types.length) {
|
||||
String xpath = this.types[i].getLocalName();
|
||||
this.builder.add(feature.getAttribute(xpath));
|
||||
++i;
|
||||
}
|
||||
fid = fid.replace(feature.getType().getTypeName(), this.target.getTypeName());
|
||||
return this.builder.buildFeature(fid);
|
||||
}
|
||||
catch (IllegalAttributeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.delegate.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,259 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import net.opengis.wfs.FeatureCollectionType;
|
||||
import net.opengis.wfs.WfsFactory;
|
||||
import org.geotools.GML;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.gml.producer.FeatureTransformer;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.wfs.WFS;
|
||||
import org.geotools.wfs.v1_0.WFSConfiguration;
|
||||
import org.geotools.xml.Configuration;
|
||||
import org.geotools.xml.Encoder;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.FeatureType;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
|
||||
public class O2GML {
|
||||
private Charset encoding = Charset.forName("UTF-8");
|
||||
private GML.Version version;
|
||||
private String prefix;
|
||||
private String namespace;
|
||||
private boolean isUseNSPrefix = true;
|
||||
private int indent = 4;
|
||||
private String defaultPrefix = "wfs";
|
||||
private String defaultNameSpace = "http://www.opengis.net/wfs";
|
||||
|
||||
public O2GML(GML.Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void encode(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||
if (this.version == GML.Version.GML2) {
|
||||
this.encodeLegacyGML2(resp, collection);
|
||||
} else if (this.version == GML.Version.GML3) {
|
||||
this.encodeLegacyGML3(resp, collection);
|
||||
} else if (this.version == GML.Version.WFS1_0) {
|
||||
Encoder e = new Encoder((Configuration)new WFSConfiguration());
|
||||
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||
e.setIndenting(true);
|
||||
if (!this.isUseNSPrefix) {
|
||||
e.setNamespaceAware(false);
|
||||
}
|
||||
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||
featureCollectionType.getFeature().add((Object)collection);
|
||||
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)resp.getOutputStream());
|
||||
} else if (this.version == GML.Version.WFS1_1) {
|
||||
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||
e.setIndenting(true);
|
||||
if (!this.isUseNSPrefix) {
|
||||
e.setNamespaceAware(false);
|
||||
}
|
||||
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||
featureCollectionType.getFeature().add((Object)collection);
|
||||
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)resp.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeLegacyGML2(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||
FeatureTransformer transform = new FeatureTransformer();
|
||||
SimpleFeatureType TYPE = (SimpleFeatureType)collection.getSchema();
|
||||
if (collection.size() > 0 && TYPE != null) {
|
||||
if (TYPE.getName().getNamespaceURI() != null && TYPE.getUserData().get("prefix") != null) {
|
||||
String typeNamespace = TYPE.getName().getNamespaceURI();
|
||||
String typePrefix = (String)TYPE.getUserData().get("prefix");
|
||||
transform.getFeatureTypeNamespaces().declareNamespace((FeatureType)TYPE, typePrefix, typeNamespace);
|
||||
String srsName = CRS.toSRS((CoordinateReferenceSystem)TYPE.getCoordinateReferenceSystem());
|
||||
if (srsName != null) {
|
||||
transform.setSrsName(srsName);
|
||||
}
|
||||
} else if (this.prefix != null && this.namespace != null) {
|
||||
transform.getFeatureTypeNamespaces().declareNamespace((FeatureType)TYPE, this.prefix, this.namespace);
|
||||
}
|
||||
}
|
||||
transform.setIndentation(this.indent);
|
||||
transform.setNumDecimals(4);
|
||||
transform.setGmlPrefixing(true);
|
||||
if (this.prefix != null && this.namespace != null) {
|
||||
transform.getFeatureTypeNamespaces().declareDefaultNamespace(this.prefix, this.namespace);
|
||||
}
|
||||
if (this.isUseNSPrefix) {
|
||||
transform.setCollectionPrefix(this.defaultPrefix);
|
||||
} else {
|
||||
transform.setCollectionPrefix(null);
|
||||
}
|
||||
transform.setCollectionNamespace(this.defaultNameSpace);
|
||||
transform.setCollectionBounding(true);
|
||||
transform.setEncoding(this.encoding);
|
||||
NamespaceSupport ns = transform.getFeatureNamespaces();
|
||||
ns.declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ServletOutputStream oStream = null;
|
||||
try {
|
||||
try {
|
||||
resp.setContentType("text/xml; charset=UTF-8");
|
||||
oStream = resp.getOutputStream();
|
||||
transform.transform((Object)collection, new StreamResult(bytes));
|
||||
resp.setContentLength(bytes.size());
|
||||
bytes.writeTo((OutputStream)oStream);
|
||||
bytes.flush();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new Exception("OutputStream has problem.", e);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (oStream != null) {
|
||||
try {
|
||||
oStream.close();
|
||||
}
|
||||
catch (IOException iOException) {}
|
||||
}
|
||||
if (bytes != null) {
|
||||
try {
|
||||
bytes.close();
|
||||
}
|
||||
catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeLegacyGML3(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||
NodeList nodeList;
|
||||
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||
e.getNamespaces().declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||
if (!this.isUseNSPrefix) {
|
||||
e.setNamespaceAware(false);
|
||||
}
|
||||
e.setIndenting(true);
|
||||
e.setIndentSize(this.indent);
|
||||
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||
featureCollectionType.getFeature().add((Object)collection);
|
||||
if (this.defaultPrefix.equalsIgnoreCase("wfs")) {
|
||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)result);
|
||||
XMLUtil.writeToResponse((HttpServletResponse)resp, (Encoder)e, (ByteArrayOutputStream)result);
|
||||
return;
|
||||
}
|
||||
org.w3c.dom.Document doc = e.encodeAsDOM((Object)featureCollectionType, WFS.FeatureCollection);
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
doc.renameNode(rootElement, this.defaultNameSpace, rootElement.getLocalName());
|
||||
rootElement.setPrefix(this.defaultPrefix);
|
||||
Attr attr = rootElement.getAttributeNode("xmlns:wfs");
|
||||
if (attr != null) {
|
||||
rootElement.removeAttributeNode(attr);
|
||||
}
|
||||
if (!this.isUseNSPrefix) {
|
||||
rootElement.setPrefix(null);
|
||||
}
|
||||
if (this.defaultPrefix.equalsIgnoreCase("gml") && (nodeList = doc.getElementsByTagNameNS("http://www.geotwo.com", "*")) != null) {
|
||||
int i = 0;
|
||||
while (i < nodeList.getLength()) {
|
||||
org.w3c.dom.Node node = nodeList.item(i);
|
||||
if (node instanceof Element) {
|
||||
doc.renameNode(node, this.defaultNameSpace, node.getLocalName());
|
||||
node.setPrefix(this.defaultPrefix);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
XMLUtil.writeToResponse((HttpServletResponse)resp, doc);
|
||||
}
|
||||
|
||||
public void encodeLegacyGML3(OutputStream out, SimpleFeatureCollection collection) throws Exception {
|
||||
Document doc = this.encodeLegacyGML3(collection);
|
||||
XMLUtil.writeToResponse((OutputStream)out, (Document)doc);
|
||||
}
|
||||
|
||||
public Document encodeLegacyGML3(SimpleFeatureCollection collection) throws Exception {
|
||||
NodeList nodeList;
|
||||
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||
e.setNamespaceAware(true);
|
||||
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||
e.getNamespaces().declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||
e.setIndenting(true);
|
||||
e.setIndentSize(this.indent);
|
||||
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||
featureCollectionType.getFeature().add((Object)collection);
|
||||
NamespaceSupport ns = e.getNamespaces();
|
||||
ns.declarePrefix("", this.defaultNameSpace);
|
||||
Document doc = e.encodeAsDOM((Object)featureCollectionType, WFS.FeatureCollection);
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
if (!this.defaultPrefix.equalsIgnoreCase("wfs")) {
|
||||
doc.renameNode(rootElement, this.defaultNameSpace, rootElement.getLocalName());
|
||||
rootElement.setPrefix(this.defaultPrefix);
|
||||
Attr attr = rootElement.getAttributeNode("xmlns:wfs");
|
||||
if (attr != null) {
|
||||
rootElement.removeAttributeNode(attr);
|
||||
}
|
||||
}
|
||||
if (!this.isUseNSPrefix) {
|
||||
rootElement.setPrefix(null);
|
||||
}
|
||||
if (this.defaultPrefix.equalsIgnoreCase("gml") && (nodeList = doc.getElementsByTagNameNS("http://www.geotwo.com", "*")) != null) {
|
||||
int i = 0;
|
||||
while (i < nodeList.getLength()) {
|
||||
org.w3c.dom.Node node = nodeList.item(i);
|
||||
if (node instanceof Element) {
|
||||
doc.renameNode(node, this.defaultNameSpace, node.getLocalName());
|
||||
node.setPrefix(this.defaultPrefix);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void setEncoding(Charset encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public void setNamespace(String prefix, String namespace) {
|
||||
this.prefix = prefix;
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public int getIndent() {
|
||||
return this.indent;
|
||||
}
|
||||
|
||||
public void setIndent(int indent) {
|
||||
this.indent = indent;
|
||||
}
|
||||
|
||||
public boolean isUseNSPrefix() {
|
||||
return this.isUseNSPrefix;
|
||||
}
|
||||
|
||||
public void setUseNSPrefix(boolean isUseDefaultNSPrefix) {
|
||||
this.isUseNSPrefix = isUseDefaultNSPrefix;
|
||||
}
|
||||
|
||||
public void setDafaultNamespace(String defaultPrefix, String defaultNameSpace) {
|
||||
this.defaultPrefix = defaultPrefix;
|
||||
this.defaultNameSpace = defaultNameSpace;
|
||||
}
|
||||
|
||||
public String getDefaultPrefix() {
|
||||
return this.defaultPrefix;
|
||||
}
|
||||
|
||||
public String getDefaultNameSpace() {
|
||||
return this.defaultNameSpace;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class O2GeometryTypeMap
|
||||
{
|
||||
static final Map<Integer, Class> O2SERVER_META_GEOMETRY_TYPE_TO_CLASS_MAP = new HashMap() { } ;
|
||||
|
||||
static final Map<String, Class> GEOMETRY_TYPE_TO_CLASS_MAP = new HashMap() { } ;
|
||||
|
||||
public static Class lookUpMeta(Integer type)
|
||||
{
|
||||
Class geometryClass = (Class)O2SERVER_META_GEOMETRY_TYPE_TO_CLASS_MAP.get(type);
|
||||
|
||||
if (geometryClass == null) {
|
||||
geometryClass = Geometry.class;
|
||||
}
|
||||
|
||||
return geometryClass;
|
||||
}
|
||||
|
||||
public static Class lookUpGeometry(String type)
|
||||
{
|
||||
Class geometryClass = (Class)GEOMETRY_TYPE_TO_CLASS_MAP.get(type);
|
||||
|
||||
if (geometryClass == null) {
|
||||
geometryClass = Geometry.class;
|
||||
}
|
||||
|
||||
return geometryClass;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class O2ImgLayer extends Layer
|
||||
{
|
||||
final O2LayerLevelSet levelSet;
|
||||
|
||||
public O2ImgLayer(AVList params)
|
||||
throws Exception
|
||||
{
|
||||
super(params);
|
||||
try
|
||||
{
|
||||
this.levelSet = ((O2LayerLevelSet)params.getValue("o2layer.conf.level.set"));
|
||||
|
||||
if ((this.levelSet == null) || (this.levelSet.size() == 0))
|
||||
throw new IOException("LevelSet has no level");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("O2ImgLayer levelset is not available. :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public O2LayerLevelSet getLevelSet()
|
||||
{
|
||||
return this.levelSet;
|
||||
}
|
||||
|
||||
public String getSourceName()
|
||||
{
|
||||
return this.levelSet.getRootPath().getAbsolutePath();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox()
|
||||
{
|
||||
return new ReferencedEnvelope(this.levelSet.getBBox(), getCRS());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class O2ImgLayerMngr {
|
||||
public static void initLayers() {
|
||||
try {
|
||||
File dir = ServerContext.getPluginsFolder();
|
||||
String fileName = String.valueOf(ServerContext.getMap().getName()) + LayerFactory.LayerType.O2IMG.getPrefix();
|
||||
File confFile = ServerUtil.findFile((File)dir, (String)fileName);
|
||||
if (confFile == null) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "Skip create O2ImgLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||
return;
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[O2IMG]", "[" + confFile.getName() + "] Now create O2ImgLayer from this configuration");
|
||||
ArrayList<O2LayerInfo> layerInfoList = O2ImgLayerMngr.parseO2ImgLayer(confFile);
|
||||
if (layerInfoList == null || layerInfoList.isEmpty()) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[" + confFile.getName() + "] Fail to create O2ImgLayer :: O2ImgLayer size is ZERO[0] from this configuration");
|
||||
return;
|
||||
}
|
||||
for (O2LayerInfo info : layerInfoList) {
|
||||
LogMngr.getInstance().logDebug("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this O2ImgLayer");
|
||||
try {
|
||||
O2ImgLayerMngr.addLayer(info.getLayerPath(), info.getLayerName(), info.getLayerCRS(), info.getDesc());
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " + "[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " + "[RefServer:" + LayerFactory.LayerType.O2IMG.getType() + "/RefSource:" + info.getLayerPath() + "]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[O2IMG]", "");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "Create O2ImgLayer Fail :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<O2LayerInfo> parseO2ImgLayer(File conf) {
|
||||
if (!conf.exists()) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] Create O2ImgLayer Fail :: O2ImgLayer configuration is not exist");
|
||||
return null;
|
||||
}
|
||||
ArrayList<O2LayerInfo> layerInfoList = new ArrayList<O2LayerInfo>();
|
||||
O2LayerInfo lInfo = null;
|
||||
BufferedReader bReader = null;
|
||||
try {
|
||||
try {
|
||||
String line;
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||
try {
|
||||
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||
lInfo = new O2LayerInfo();
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||
lInfo.setActivate(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||
lInfo.setLayerName(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.CRS")) {
|
||||
lInfo.setLayerCRS(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.PATH")) {
|
||||
lInfo.setLayerPath(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (line.toUpperCase().contains("LAYER.DESC")) {
|
||||
lInfo.setDesc(line.split("\\=")[1]);
|
||||
continue;
|
||||
}
|
||||
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||
if (lInfo != null && lInfo.isAvailable()) {
|
||||
layerInfoList.add(lInfo);
|
||||
} else {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] Skip this O2ImgLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||
}
|
||||
lInfo = null;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] O2ImgLayer configuration file is not valid :: " + e.getMessage());
|
||||
try {
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
catch (IOException e2) {
|
||||
bReader = null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (bReader != null) {
|
||||
bReader.close();
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
bReader = null;
|
||||
}
|
||||
}
|
||||
return layerInfoList;
|
||||
}
|
||||
|
||||
public static O2ImgLayer addLayer(File layerPath, String layerName, CoordinateReferenceSystem crs, String desc) throws Exception {
|
||||
if (layerPath == null || !layerPath.exists() || layerPath.isFile()) {
|
||||
throw new IOException("O2ImgLayer levelset is not exist [" + layerPath.getAbsolutePath() + "]");
|
||||
}
|
||||
if (ServerUtil.isNullString((String)layerName)) {
|
||||
throw new IOException("O2ImgLayer LayerName is null");
|
||||
}
|
||||
if (crs == null) {
|
||||
throw new IOException("O2ImgLayer LayerCRS is null");
|
||||
}
|
||||
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet((LayerFactory.LayerType)LayerFactory.LayerType.O2IMG, (File)layerPath);
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||
params.setValue("conf.service.ref.server", (Object)LayerFactory.LayerType.O2IMG.getType());
|
||||
params.setValue("conf.service.ref.source", (Object)layerPath.getParent());
|
||||
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||
params.setValue("conf.service.sld", null);
|
||||
params.setValue("conf.service.use.cache", (Object)false);
|
||||
params.setValue("conf.service.last.update", null);
|
||||
params.setValue("conf.service.description", (Object)desc);
|
||||
params.setValue("o2layer.conf.level.set", (Object)lvlSet);
|
||||
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.O2IMG, (AVList)params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
return (O2ImgLayer)layer;
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2IMG);
|
||||
try {
|
||||
O2ImgLayerMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "Success to reload O2ImgLayers.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "Fail to reload O2ImgLayers. Now use previous O2ImgLayers :: " + e);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
|
||||
public class O2LayerIndex
|
||||
{
|
||||
Envelope bbox;
|
||||
int row;
|
||||
int col;
|
||||
int blockIndex;
|
||||
long filePosition;
|
||||
|
||||
public O2LayerIndex(Envelope bbox, int row, int col)
|
||||
{
|
||||
this.bbox = bbox;
|
||||
this.row = row;
|
||||
this.col = col;
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return this.row;
|
||||
}
|
||||
|
||||
public int getCol() {
|
||||
return this.col;
|
||||
}
|
||||
|
||||
public void setBlockIndex(int idx) {
|
||||
this.blockIndex = idx;
|
||||
}
|
||||
|
||||
public int getBlockIndex() {
|
||||
return this.blockIndex;
|
||||
}
|
||||
|
||||
public void setFilePosition(long pos) {
|
||||
this.filePosition = pos;
|
||||
}
|
||||
|
||||
public long getFilePosition() {
|
||||
return this.filePosition;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.File;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class O2LayerInfo {
|
||||
private String layerName;
|
||||
private boolean activate = false;
|
||||
private CoordinateReferenceSystem layerCRS;
|
||||
private File layerPath;
|
||||
private String desc;
|
||||
private Float minData = null;
|
||||
private Float maxData = null;
|
||||
private Float noData = null;
|
||||
|
||||
public String getLayerName() {
|
||||
return this.layerName;
|
||||
}
|
||||
|
||||
public boolean isActivate() {
|
||||
return this.activate;
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem getLayerCRS() {
|
||||
return this.layerCRS;
|
||||
}
|
||||
|
||||
public File getLayerPath() {
|
||||
return this.layerPath;
|
||||
}
|
||||
|
||||
public void setLayerName(String name) {
|
||||
if (ServerUtil.isNullString((String)name)) {
|
||||
this.layerName = null;
|
||||
}
|
||||
this.layerName = name.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public void setActivate(String actiStr) {
|
||||
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||
}
|
||||
|
||||
public void setLayerCRS(String crsName) {
|
||||
this.layerCRS = CRSMngr.getCRS((String)crsName);
|
||||
}
|
||||
|
||||
public void setLayerPath(String path) {
|
||||
if (ServerUtil.isNullString((String)path)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
File file = new File(path.trim());
|
||||
if (file.exists()) {
|
||||
this.layerPath = file;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.layerPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public void setMinData(String min) {
|
||||
try {
|
||||
this.minData = Float.valueOf(min);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.minData = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxData(String max) {
|
||||
try {
|
||||
this.maxData = Float.valueOf(max);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.maxData = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNoData(String no) {
|
||||
try {
|
||||
this.noData = Float.valueOf(no);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.noData = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getMinData() {
|
||||
return this.minData;
|
||||
}
|
||||
|
||||
public Float getMaxData() {
|
||||
return this.maxData;
|
||||
}
|
||||
|
||||
public Float getNoData() {
|
||||
return this.noData;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
if (!this.activate) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.activate] is False");
|
||||
return false;
|
||||
}
|
||||
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.name] is Empty");
|
||||
return false;
|
||||
}
|
||||
if (this.layerPath == null) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.path] is not exist");
|
||||
return false;
|
||||
}
|
||||
if (this.layerCRS == null) {
|
||||
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.crs] is not available");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.File;
|
||||
|
||||
public class O2LayerLevel
|
||||
{
|
||||
private final File levelPath;
|
||||
private String version;
|
||||
private String type;
|
||||
private int level;
|
||||
private Envelope bbox;
|
||||
private double minZ;
|
||||
private double maxZ;
|
||||
private double resolutionX;
|
||||
private double resolutionY;
|
||||
private int totalPixelSizeX;
|
||||
private int totalPixelSizeY;
|
||||
private int tileCountX;
|
||||
private int tileCountY;
|
||||
private int tileSizeX;
|
||||
private int tileSizeY;
|
||||
private int blockCount;
|
||||
private byte[] reserved = new byte[32];
|
||||
|
||||
public O2LayerLevel(File dir) throws Exception {
|
||||
this.levelPath = dir;
|
||||
}
|
||||
|
||||
public File getLevelPath() {
|
||||
return this.levelPath;
|
||||
}
|
||||
|
||||
void setVersion(String version) {
|
||||
if (version.length() != 8) {
|
||||
version = "O2I1.0.0";
|
||||
return;
|
||||
}
|
||||
|
||||
this.version = version.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
void setType(String type)
|
||||
{
|
||||
if (type.length() != 8) {
|
||||
type = "DEM/FLT ";
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = type.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
void setLevel(int lvl) {
|
||||
this.level = lvl;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
void setBBox(Envelope box) {
|
||||
this.bbox = box;
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
void setZ(double min, double max) {
|
||||
this.minZ = min;
|
||||
this.maxZ = max;
|
||||
}
|
||||
|
||||
public double getMinZ() {
|
||||
return this.minZ;
|
||||
}
|
||||
|
||||
public double getMaxZ() {
|
||||
return this.maxZ;
|
||||
}
|
||||
|
||||
void setResolution(double x, double y) {
|
||||
this.resolutionX = Math.abs(x);
|
||||
this.resolutionY = Math.abs(y);
|
||||
}
|
||||
|
||||
public double getResolutionX() {
|
||||
return this.resolutionX;
|
||||
}
|
||||
|
||||
public double getResolutionY() {
|
||||
return this.resolutionY;
|
||||
}
|
||||
|
||||
void setTotalPixelSize(int x, int y) {
|
||||
this.totalPixelSizeX = x;
|
||||
this.totalPixelSizeY = y;
|
||||
}
|
||||
|
||||
public int getTotalPixelSizeX() {
|
||||
return this.totalPixelSizeX;
|
||||
}
|
||||
|
||||
public int getTotalPixelSizeY() {
|
||||
return this.totalPixelSizeY;
|
||||
}
|
||||
|
||||
void setTileCount(int x, int y) {
|
||||
this.tileCountX = x;
|
||||
this.tileCountY = y;
|
||||
}
|
||||
|
||||
public int getTileCountX() {
|
||||
return this.tileCountX;
|
||||
}
|
||||
|
||||
public int getTileCountY() {
|
||||
return this.tileCountY;
|
||||
}
|
||||
|
||||
void setTileSize(int x, int y) {
|
||||
this.tileSizeX = x;
|
||||
this.tileSizeY = y;
|
||||
}
|
||||
|
||||
public int getTileSizeX() {
|
||||
return this.tileSizeX;
|
||||
}
|
||||
|
||||
public int getTileSizeY() {
|
||||
return this.tileSizeY;
|
||||
}
|
||||
|
||||
void setBlockCount(int count) {
|
||||
this.blockCount = count;
|
||||
}
|
||||
|
||||
public int getBlockCount() {
|
||||
return this.blockCount;
|
||||
}
|
||||
|
||||
void setReserved(byte[] in) {
|
||||
if ((in == null) || (in.length != this.reserved.length)) {
|
||||
for (int i = 0; i < this.reserved.length; i++) {
|
||||
this.reserved[i] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.reserved = in;
|
||||
}
|
||||
|
||||
public byte[] getReserved() {
|
||||
return this.reserved;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.File;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class O2LayerLevelSet
|
||||
{
|
||||
private final File rootPath;
|
||||
private final LayerFactory.LayerType layerType;
|
||||
private Envelope bbox;
|
||||
TreeMap<Integer, O2LayerLevel> levels = new TreeMap();
|
||||
private Float minData;
|
||||
private Float maxData;
|
||||
private Float noData;
|
||||
|
||||
public O2LayerLevelSet(LayerFactory.LayerType type, File dir)
|
||||
{
|
||||
this.layerType = type;
|
||||
this.rootPath = dir;
|
||||
}
|
||||
|
||||
public File getRootPath() {
|
||||
return this.rootPath;
|
||||
}
|
||||
|
||||
public LayerFactory.LayerType getLayerType() {
|
||||
return this.layerType;
|
||||
}
|
||||
|
||||
void addLevel(O2LayerLevel level)
|
||||
{
|
||||
this.levels.put(Integer.valueOf(level.getLevel()), level);
|
||||
|
||||
if (this.bbox == null)
|
||||
this.bbox = level.getBBox();
|
||||
else
|
||||
this.bbox.expandToInclude(this.bbox);
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevelByResolution(double res)
|
||||
{
|
||||
O2LayerLevel level = null;
|
||||
|
||||
for (O2LayerLevel lvl : this.levels.values()) {
|
||||
if (level == null) {
|
||||
level = lvl;
|
||||
}
|
||||
else if (Math.abs(level.getResolutionX() - res) >
|
||||
Math.abs(lvl.getResolutionX() - res)) {
|
||||
level = lvl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevelByIndex(int idx) {
|
||||
return (O2LayerLevel)this.levels.get(Integer.valueOf(idx));
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevel(int idx) {
|
||||
return (O2LayerLevel)this.levels.values().toArray()[idx];
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.levels.size();
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public void setMinData(Float min) {
|
||||
this.minData = min;
|
||||
}
|
||||
|
||||
public void setMaxData(Float max) {
|
||||
this.maxData = max;
|
||||
}
|
||||
|
||||
public void setNoData(Float no) {
|
||||
this.noData = no;
|
||||
}
|
||||
|
||||
public Float getMinData() {
|
||||
return this.minData;
|
||||
}
|
||||
|
||||
public Float getMaxData() {
|
||||
return this.maxData;
|
||||
}
|
||||
|
||||
public Float getNoData() {
|
||||
return this.noData;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,644 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.awt.image.SampleModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.media.jai.RasterFactory;
|
||||
import org.geotools.coverage.GridSampleDimension;
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.coverage.grid.GridCoverageFactory;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class O2LayerUtil
|
||||
{
|
||||
public static final String NODATA_PROPERTY_NAME = "GC_NODATA";
|
||||
public static final String MINVALUE_PROPERTY_NAME = "GC_MINVALUE";
|
||||
public static final String MAXVALUE_PROPERTY_NAME = "GC_MAXVALUE";
|
||||
private static final int INDEX_HEADER_BYTE = 144;
|
||||
private static final int INDEX_TILEINFO_BYTE = 20;
|
||||
private static final GridCoverageFactory gcFactory = new GridCoverageFactory();
|
||||
|
||||
public static String readString(FileChannel fc, int capacity) throws Exception
|
||||
{
|
||||
ByteBuffer byteData = ByteBuffer.allocate(capacity);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
|
||||
String result = new String(byteData.order(ByteOrder.nativeOrder()).array());
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int readInt(FileChannel fc) throws Exception
|
||||
{
|
||||
ByteBuffer byteData = ByteBuffer.allocate(4);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
|
||||
int result = byteData.order(ByteOrder.nativeOrder()).getInt();
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double readDouble(FileChannel fc) throws Exception
|
||||
{
|
||||
ByteBuffer byteData = ByteBuffer.allocate(8);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
|
||||
double result = byteData.order(ByteOrder.nativeOrder()).getDouble();
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static O2LayerLevelSet createLevelSet(LayerFactory.LayerType type, File dir)
|
||||
throws Exception
|
||||
{
|
||||
if ((dir == null) ||
|
||||
(!dir.exists()) ||
|
||||
(dir.isFile())) {
|
||||
throw new IOException("O2ImgLayer or O2DemLayer dataset is not exist [" + dir.getAbsolutePath() + "]");
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
throw new IOException("O2ImgLayer or O2DemLayer type is Null");
|
||||
}
|
||||
|
||||
File[] levels = dir.listFiles(new FileFilter()
|
||||
{
|
||||
String regex = "^LEVEL[0-9]+";
|
||||
|
||||
public boolean accept(File path)
|
||||
{
|
||||
if ((path.isDirectory()) &&
|
||||
(path.getName().toUpperCase().matches(this.regex))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
O2LayerLevelSet lvlSet = new O2LayerLevelSet(type, dir);
|
||||
findValueInfo(lvlSet);
|
||||
|
||||
LogMngr.getInstance().logDebug("[O2INDEX]",
|
||||
"[" + dir.getName() + "] This layer has [" + levels.length + "] level. Now find index file for eatch level");
|
||||
for (File level : levels) {
|
||||
try {
|
||||
O2LayerLevel idx = createLevel(type, level);
|
||||
lvlSet.addLevel(idx);
|
||||
LogMngr.getInstance().logDebug("[O2INDEX]",
|
||||
"[" + dir.getName() + "] Success to add this Level [" + level.getName() + "]");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2INDEX]",
|
||||
"[" + dir.getName() + "] Fail to add this Level [" + level.getName() + "] :: " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (lvlSet.size() == 0) {
|
||||
throw new IOException("[" + dir.getName() + "] This layer has no level.");
|
||||
}
|
||||
|
||||
return lvlSet;
|
||||
}
|
||||
|
||||
private static void findValueInfo(O2LayerLevelSet lvlSet)
|
||||
throws Exception
|
||||
{
|
||||
RandomAccessFile raf = null;
|
||||
try
|
||||
{
|
||||
File infoFile = new File(lvlSet.getRootPath(), "/info.o2img");
|
||||
|
||||
LogMngr.getInstance().logDebug("[O2INFO]",
|
||||
"Now find info.o2img for O2IMG & O2DEM from here [" + infoFile.getAbsolutePath() + "]");
|
||||
|
||||
raf = new RandomAccessFile(infoFile, "r");
|
||||
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
|
||||
String type = raf.readLine();
|
||||
type = type.trim().toUpperCase();
|
||||
if (lvlSet.getLayerType() == LayerFactory.LayerType.O2IMG) {
|
||||
if (!type.equalsIgnoreCase("IMAGE")) {
|
||||
throw new Exception("This level is not O2IMG type");
|
||||
}
|
||||
}
|
||||
else if (!type.equalsIgnoreCase("DEM")) {
|
||||
throw new Exception("This level is not O2DEM type");
|
||||
}
|
||||
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
|
||||
String minmax = raf.readLine();
|
||||
if (minmax != null) {
|
||||
String[] value = minmax.split("\\s+");
|
||||
lvlSet.setMinData(Float.valueOf(value[0]));
|
||||
lvlSet.setMaxData(Float.valueOf(value[1]));
|
||||
}
|
||||
|
||||
String nodata = raf.readLine();
|
||||
if (nodata != null)
|
||||
lvlSet.setNoData(Float.valueOf(nodata));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[O2INFO]",
|
||||
"Fail to find info now use default or user setting");
|
||||
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException)
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static O2LayerLevel createLevel(LayerFactory.LayerType type, File dir)
|
||||
throws Exception
|
||||
{
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
try
|
||||
{
|
||||
File idxFile = new File(dir, "/index.o2img");
|
||||
|
||||
raf = new RandomAccessFile(idxFile, "r");
|
||||
channel = raf.getChannel();
|
||||
|
||||
O2LayerLevel o2Level = new O2LayerLevel(dir);
|
||||
|
||||
o2Level.setVersion(readString(channel, 8));
|
||||
|
||||
o2Level.setType(readString(channel, 8));
|
||||
if (type == LayerFactory.LayerType.O2IMG) {
|
||||
if (!o2Level.getType().contains("IMG")) {
|
||||
throw new Exception("This level is not O2IMG type");
|
||||
}
|
||||
}
|
||||
else if (!o2Level.getType().contains("DEM")) {
|
||||
throw new Exception("This level is not O2DEM type");
|
||||
}
|
||||
|
||||
o2Level.setLevel(readInt(channel));
|
||||
|
||||
double minx = readDouble(channel);
|
||||
double maxx = readDouble(channel);
|
||||
double miny = readDouble(channel);
|
||||
double maxy = readDouble(channel);
|
||||
o2Level.setBBox(new Envelope(minx, maxx, miny, maxy));
|
||||
|
||||
double minz = readDouble(channel);
|
||||
double maxz = readDouble(channel);
|
||||
o2Level.setZ(minz, maxz);
|
||||
|
||||
double resX = readDouble(channel);
|
||||
double resY = readDouble(channel);
|
||||
o2Level.setResolution(resX, resY);
|
||||
|
||||
int tPixelSizeX = readInt(channel);
|
||||
int tPixelSizeY = readInt(channel);
|
||||
o2Level.setTotalPixelSize(tPixelSizeX, tPixelSizeY);
|
||||
|
||||
int tileCountY = readInt(channel);
|
||||
int tileCountX = readInt(channel);
|
||||
o2Level.setTileCount(tileCountX, tileCountY);
|
||||
|
||||
int tileSizeX = readInt(channel);
|
||||
int tileSizeY = readInt(channel);
|
||||
o2Level.setTileSize(tileSizeX, tileSizeY);
|
||||
|
||||
o2Level.setBlockCount(readInt(channel));
|
||||
|
||||
return o2Level;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
if ((channel != null) && (channel.isOpen()))
|
||||
try {
|
||||
channel.close();
|
||||
}
|
||||
catch (IOException localIOException2)
|
||||
{
|
||||
}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException3)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getO2Img(File levelPath, int blockIdx, long bPos)
|
||||
throws Exception
|
||||
{
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
ByteBuffer byteData = null;
|
||||
ByteArrayInputStream inStream = null;
|
||||
try
|
||||
{
|
||||
File blockFile = new File(levelPath, "/block" + blockIdx + ".o2blk");
|
||||
|
||||
raf = new RandomAccessFile(blockFile, "r");
|
||||
channel = raf.getChannel();
|
||||
|
||||
channel.position(bPos);
|
||||
int size = readInt(channel);
|
||||
|
||||
raf.skipBytes(8);
|
||||
|
||||
byteData = ByteBuffer.allocate(size - 12);
|
||||
channel.read(byteData);
|
||||
byteData.flip();
|
||||
|
||||
inStream = new ByteArrayInputStream(byteData.order(ByteOrder.nativeOrder()).array());
|
||||
BufferedImage bImage = ImageIO.read(inStream);
|
||||
|
||||
return bImage;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[O2LayerUtil] getO2Img fail :: " + e);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ((channel != null) && (channel.isOpen()))
|
||||
try {
|
||||
channel.close();
|
||||
}
|
||||
catch (IOException localIOException2)
|
||||
{
|
||||
}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException3)
|
||||
{
|
||||
}
|
||||
if (byteData != null) {
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
}
|
||||
|
||||
if (inStream != null) {
|
||||
inStream.close();
|
||||
inStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float[][] getO2Dem(File levelPath, int blockIdx, long bPos, int width, int height, Float min, Float max, Float noData)
|
||||
throws Exception
|
||||
{
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
ByteBuffer byteData = null;
|
||||
ByteArrayInputStream inStream = null;
|
||||
try
|
||||
{
|
||||
File blockFile = new File(levelPath, "/block" + blockIdx + ".o2blk");
|
||||
|
||||
raf = new RandomAccessFile(blockFile, "r");
|
||||
channel = raf.getChannel();
|
||||
|
||||
channel.position(bPos);
|
||||
int size = readInt(channel);
|
||||
int matrixSize = size - 12;
|
||||
|
||||
raf.skipBytes(8);
|
||||
|
||||
byteData = ByteBuffer.allocate(matrixSize);
|
||||
channel.read(byteData);
|
||||
byteData.flip();
|
||||
|
||||
inStream = new ByteArrayInputStream(byteData.array());
|
||||
|
||||
float[][] data = new float[height][width];
|
||||
byte[] read = new byte[4];
|
||||
|
||||
if (noData == null) {
|
||||
noData = Float.valueOf((0.0F / 0.0F));
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
inStream.read(read);
|
||||
float dem = ByteBuffer.wrap(read).order(ByteOrder.nativeOrder()).getFloat();
|
||||
|
||||
if ((min != null) && (dem < min.floatValue())) {
|
||||
data[y][x] = noData.floatValue();
|
||||
}
|
||||
else if ((max != null) && (max.floatValue() < dem)) {
|
||||
data[y][x] = noData.floatValue();
|
||||
}
|
||||
else {
|
||||
data[y][x] = dem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[O2LayerUtil] getO2Img fail :: " + e);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ((channel != null) && (channel.isOpen()))
|
||||
try {
|
||||
channel.close();
|
||||
}
|
||||
catch (IOException localIOException2)
|
||||
{
|
||||
}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException3)
|
||||
{
|
||||
}
|
||||
if (byteData != null) {
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
}
|
||||
|
||||
if (inStream != null) {
|
||||
inStream.close();
|
||||
inStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getMap(O2LayerLevelSet levelSet, ReferencedEnvelope bbox, int width, int height)
|
||||
throws Exception
|
||||
{
|
||||
BufferedImage image = new BufferedImage(width, height, 6);
|
||||
|
||||
Envelope targetBBox = bbox.intersection(levelSet.getBBox());
|
||||
if ((targetBBox == null) || (targetBBox.isNull())) {
|
||||
return image;
|
||||
}
|
||||
|
||||
double resX = bbox.getWidth() / width;
|
||||
double resY = bbox.getHeight() / height;
|
||||
|
||||
double res = Math.max(resX, resY);
|
||||
|
||||
O2LayerLevel level = levelSet.getLevelByResolution(res);
|
||||
|
||||
ArrayList<O2LayerIndex> idxs = calBlockIndex(level, bbox);
|
||||
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
for (O2LayerIndex idx : idxs)
|
||||
{
|
||||
BufferedImage o2img = getO2Img(level.getLevelPath(), idx.getBlockIndex(), idx.getFilePosition());
|
||||
|
||||
Rectangle tileArea = ServerUtil.calPaintArea(new Rectangle(width, height), bbox, idx.getBBox());
|
||||
|
||||
int startX = tileArea.x < 0 ? 0 : tileArea.x;
|
||||
int startY = tileArea.y < 0 ? 0 : tileArea.y;
|
||||
int endX = tileArea.getMaxX() > width ? width : (int)tileArea.getMaxX();
|
||||
int endY = tileArea.getMaxY() > height ? height : (int)tileArea.getMaxY();
|
||||
|
||||
double scaleX = level.getTileSizeX() / tileArea.width;
|
||||
double scaleY = level.getTileSizeY() / tileArea.height;
|
||||
|
||||
graphics.drawImage(o2img,
|
||||
startX, startY, endX, endY,
|
||||
(int)(Math.abs(tileArea.x - startX) * scaleX),
|
||||
(int)(Math.abs(tileArea.y - startY) * scaleY),
|
||||
(int)(Math.abs(tileArea.x - endX) * scaleX),
|
||||
(int)(Math.abs(tileArea.y - endY) * scaleY),
|
||||
null);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static GridCoverage2D getCoverage(O2LayerLevelSet levelSet, ReferencedEnvelope bbox, int width, int height)
|
||||
throws Exception
|
||||
{
|
||||
WritableRaster raster =
|
||||
RasterFactory.createBandedRaster(4, width, height, 1, new Point(0, 0));
|
||||
|
||||
Float noData = levelSet.getNoData();
|
||||
if (noData == null) noData = Float.valueOf((0.0F / 0.0F));
|
||||
for (int c = 0; c < width; c++) {
|
||||
for (int r = 0; r < height; r++) {
|
||||
raster.setSample(c, r, 0, noData.floatValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Envelope targetBBox = bbox.intersection(levelSet.getBBox());
|
||||
if ((targetBBox == null) || (targetBBox.isNull())) {
|
||||
return gcFactory.create("DEM", raster, bbox);
|
||||
}
|
||||
|
||||
double resX = bbox.getWidth() / width;
|
||||
double resY = bbox.getHeight() / height;
|
||||
|
||||
double res = Math.max(resX, resY);
|
||||
|
||||
O2LayerLevel level = levelSet.getLevelByResolution(res);
|
||||
|
||||
ArrayList<O2LayerIndex> idxs = calBlockIndex(level, bbox);
|
||||
int endY = 1;
|
||||
int row = 0;
|
||||
// thkim 로직이 이상함
|
||||
Iterator<O2LayerIndex> localIterator = idxs.iterator();
|
||||
for (; row < endY; localIterator.hasNext()
|
||||
)
|
||||
{
|
||||
O2LayerIndex idx = (O2LayerIndex)localIterator.next();
|
||||
|
||||
float[][] o2dem = getO2Dem(
|
||||
level.getLevelPath(), idx.getBlockIndex(), idx.getFilePosition(),
|
||||
level.getTileSizeX() + 1, level.getTileSizeY() + 1,
|
||||
levelSet.getMinData(), levelSet.getMaxData(), noData);
|
||||
|
||||
Rectangle tileArea = ServerUtil.calPaintArea(new Rectangle(width, height), bbox, idx.getBBox());
|
||||
|
||||
int startX = tileArea.x < 0 ? 0 : tileArea.x;
|
||||
int startY = tileArea.y < 0 ? 0 : tileArea.y;
|
||||
int endX = tileArea.getMaxX() > width ? width : (int)tileArea.getMaxX();
|
||||
endY = tileArea.getMaxY() > height ? height : (int)tileArea.getMaxY();
|
||||
|
||||
double scaleX = (level.getTileSizeX() + 1) / tileArea.width;
|
||||
double scaleY = (level.getTileSizeY() + 1) / tileArea.height;
|
||||
|
||||
row = startY;
|
||||
//continue;
|
||||
for (int col = startX; col < endX; col++)
|
||||
{
|
||||
int getRow = (int)(Math.abs(tileArea.y - row) * scaleY);
|
||||
int getCol = (int)(Math.abs(tileArea.x - col) * scaleX);
|
||||
|
||||
int size = 1;
|
||||
float avr = o2dem[getRow][getCol];
|
||||
if (getRow - 1 >= 0) {
|
||||
avr += o2dem[(getRow - 1)][getCol];
|
||||
size++;
|
||||
}
|
||||
if (getRow + 1 < level.getTileSizeY() + 1) {
|
||||
avr += o2dem[(getRow + 1)][getCol];
|
||||
size++;
|
||||
}
|
||||
if (getCol - 1 >= 0) {
|
||||
avr += o2dem[getRow][(getCol - 1)];
|
||||
size++;
|
||||
}
|
||||
if (getCol + 1 < level.getTileSizeX() + 1) {
|
||||
avr += o2dem[getRow][(getCol + 1)];
|
||||
size++;
|
||||
}
|
||||
|
||||
raster.setSample(col, row, 0, avr / size);
|
||||
}
|
||||
row++;
|
||||
}
|
||||
|
||||
Map propMap = new HashMap();
|
||||
propMap.put("GC_MINVALUE", levelSet.getMinData());
|
||||
propMap.put("GC_MAXVALUE", levelSet.getMaxData());
|
||||
propMap.put("GC_NODATA", levelSet.getNoData());
|
||||
|
||||
GridSampleDimension[] bands = new GridSampleDimension[raster.getNumBands()];
|
||||
ColorModel model = bands[0].getColorModel(0, bands.length, raster.getSampleModel().getDataType());
|
||||
RenderedImage image = new BufferedImage(model, raster, false, null);
|
||||
|
||||
return new GridCoverageFactory().create("DEM", image, bbox, null, null, propMap);
|
||||
}
|
||||
|
||||
public static ArrayList<O2LayerIndex> calBlockIndex(O2LayerLevel level, Envelope cBBox)
|
||||
throws Exception
|
||||
{
|
||||
ArrayList result = new ArrayList();
|
||||
|
||||
Envelope pBBox = level.getBBox();
|
||||
double width = level.getTileSizeX() * level.getResolutionX();
|
||||
double height = level.getTileSizeY() * level.getResolutionY();
|
||||
|
||||
int nROffX = (int)((cBBox.getMinX() - pBBox.getMinX()) / level.getResolutionX());
|
||||
int nROffY = (int)((pBBox.getMaxY() - cBBox.getMaxY()) / level.getResolutionY());
|
||||
int nRWidth = (int)((cBBox.getMaxX() - pBBox.getMinX()) / level.getResolutionX()) - nROffX + 1;
|
||||
int nRHeight = (int)((pBBox.getMaxY() - cBBox.getMinY()) / level.getResolutionY()) - nROffY + 1;
|
||||
|
||||
int sCol = nROffX / level.getTileSizeX();
|
||||
int eCol = (nROffX + nRWidth) / level.getTileSizeX();
|
||||
int sRow = nROffY / level.getTileSizeY();
|
||||
int eRow = (nROffY + nRHeight) / level.getTileSizeY();
|
||||
|
||||
sCol = sCol < 0 ? 0 : sCol;
|
||||
eCol = level.getTileCountX() <= eCol ? level.getTileCountX() - 1 : eCol;
|
||||
sRow = sRow < 0 ? 0 : sRow;
|
||||
eRow = level.getTileCountY() <= eRow ? level.getTileCountY() - 1 : eRow;
|
||||
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
try {
|
||||
File idxFile = new File(level.getLevelPath(), "/index.o2img");
|
||||
|
||||
raf = new RandomAccessFile(idxFile, "r");
|
||||
channel = raf.getChannel();
|
||||
|
||||
for (int r = sRow; r <= eRow; r++) {
|
||||
for (int c = sCol; c <= eCol; c++)
|
||||
{
|
||||
Envelope bbox = new Envelope(
|
||||
pBBox.getMinX() + width * c,
|
||||
pBBox.getMinX() + width * (c + 1),
|
||||
pBBox.getMaxY() - height * (r + 1),
|
||||
pBBox.getMaxY() - height * r);
|
||||
|
||||
O2LayerIndex idx = new O2LayerIndex(bbox, r, c);
|
||||
|
||||
channel.position(144 +
|
||||
(level.getTileCountX() * r + c) * 20);
|
||||
|
||||
idx.setBlockIndex(readInt(channel));
|
||||
idx.setFilePosition(readInt(channel));
|
||||
|
||||
result.add(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ((channel != null) && (channel.isOpen()))
|
||||
try {
|
||||
channel.close();
|
||||
}
|
||||
catch (IOException localIOException)
|
||||
{
|
||||
}
|
||||
if (raf != null) {
|
||||
try {
|
||||
raf.close();
|
||||
}
|
||||
catch (IOException localIOException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
|
||||
import ar.com.hjg.pngj.FilterType;
|
||||
import ar.com.hjg.pngj.ImageInfo;
|
||||
import ar.com.hjg.pngj.ImageLineByte;
|
||||
import ar.com.hjg.pngj.ImageLineHelper;
|
||||
import ar.com.hjg.pngj.ImageLineInt;
|
||||
import ar.com.hjg.pngj.PngWriter;
|
||||
import ar.com.hjg.pngj.PngjException;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ComponentSampleModel;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.SinglePixelPackedSampleModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class O2PngWriter
|
||||
{
|
||||
public static void writeRgb8(BufferedImage buf, OutputStream os)
|
||||
{
|
||||
ImageInfo imi = getImageInfo(buf);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
|
||||
ImageLineInt line = new ImageLineInt(imi);
|
||||
buf.getRaster();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
for (int col = 0; col < imi.cols; col++) {
|
||||
int p = buf.getRGB(col, row);
|
||||
if (imi.alpha)
|
||||
ImageLineHelper.setPixelRGBA8(line, col, p);
|
||||
else {
|
||||
ImageLineHelper.setPixelRGB8(line, col, p);
|
||||
}
|
||||
}
|
||||
pngw.writeRow(line, row);
|
||||
}
|
||||
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writeRgb8Ori(BufferedImage buf, OutputStream os)
|
||||
{
|
||||
ImageInfo imi = getImageInfo(buf);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
|
||||
ImageLineInt line = new ImageLineInt(imi);
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
for (int col = 0; col < imi.cols; col++) {
|
||||
int p = buf.getRGB(col, row);
|
||||
if (imi.alpha)
|
||||
ImageLineHelper.setPixelRGBA8(line, col, p);
|
||||
else {
|
||||
ImageLineHelper.setPixelRGB8(line, col, p);
|
||||
}
|
||||
}
|
||||
pngw.writeRow(line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writePNG(BufferedImage bi, OutputStream os)
|
||||
{
|
||||
if (bi.getType() == 2)
|
||||
writeTYPE_INT_ARGB(bi, os);
|
||||
else if (bi.getType() == 6)
|
||||
writeTYPE_4BYTE_ABGR(bi, os);
|
||||
else
|
||||
writeRgb8(bi, os);
|
||||
}
|
||||
|
||||
public static void writeTYPE_INT_ARGB(BufferedImage bi, OutputStream os)
|
||||
{
|
||||
if (bi.getType() != 2) {
|
||||
throw new PngjException("This method expects BufferedImage.TYPE_INT_ARGB");
|
||||
}
|
||||
|
||||
ImageInfo imi = getImageInfo(bi);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
|
||||
DataBufferInt db = (DataBufferInt)bi.getRaster().getDataBuffer();
|
||||
if (db.getNumBanks() != 1) {
|
||||
throw new PngjException("This method expects one bank");
|
||||
}
|
||||
|
||||
SinglePixelPackedSampleModel samplemodel = (SinglePixelPackedSampleModel)bi.getSampleModel();
|
||||
ImageLineByte line = new ImageLineByte(imi);
|
||||
int[] dbbuf = db.getData();
|
||||
byte[] scanline = line.getScanline();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
int elem = samplemodel.getOffset(0, row);
|
||||
int col = 0; for (int j = 0; col < imi.cols; col++) {
|
||||
int sample = dbbuf[(elem++)];
|
||||
scanline[(j++)] = ((byte)((sample & 0xFF0000) >> 16));
|
||||
scanline[(j++)] = ((byte)((sample & 0xFF00) >> 8));
|
||||
scanline[(j++)] = ((byte)(sample & 0xFF));
|
||||
scanline[(j++)] = ((byte)((sample & 0xFF000000) >> 24 & 0xFF));
|
||||
}
|
||||
pngw.writeRow(line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writeTYPE_4BYTE_ABGR(BufferedImage bi, OutputStream os) {
|
||||
if (bi.getType() != 6) {
|
||||
throw new PngjException("This method expects BufferedImage.TYPE_4BYTE_ABGR");
|
||||
}
|
||||
|
||||
ImageInfo imi = getImageInfo(bi);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
|
||||
DataBufferByte db = (DataBufferByte)bi.getRaster().getDataBuffer();
|
||||
ComponentSampleModel samplemodel = (ComponentSampleModel)bi.getSampleModel();
|
||||
ImageLineByte line = new ImageLineByte(imi);
|
||||
if (db.getNumBanks() != 1) {
|
||||
throw new PngjException("This method expects one bank");
|
||||
}
|
||||
|
||||
byte[] dbbuf = db.getData();
|
||||
byte[] scanline = line.getScanline();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
int elem = samplemodel.getOffset(0, row);
|
||||
int col = 0; for (int j = 0; col < imi.cols; elem += 7) {
|
||||
scanline[(j++)] = dbbuf[(elem--)];
|
||||
scanline[(j++)] = dbbuf[(elem--)];
|
||||
scanline[(j++)] = dbbuf[(elem--)];
|
||||
scanline[(j++)] = dbbuf[elem];
|
||||
|
||||
col++;
|
||||
}
|
||||
|
||||
pngw.writeRow(line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
private static ImageInfo getImageInfo(BufferedImage buf) {
|
||||
int buftype = buf.getType();
|
||||
boolean alpha = false; boolean indexed = false; boolean alphapre = false; boolean gray = false; boolean depth16 = false;
|
||||
switch (buftype) {
|
||||
case 2:
|
||||
case 6:
|
||||
alpha = true;
|
||||
case 3:
|
||||
case 7:
|
||||
alphapre = true;
|
||||
break;
|
||||
case 10:
|
||||
case 12:
|
||||
gray = true;
|
||||
case 11:
|
||||
depth16 = true;
|
||||
break;
|
||||
case 13:
|
||||
if ((buf.getColorModel() instanceof IndexColorModel))
|
||||
indexed = true; break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 8:
|
||||
case 9:
|
||||
}
|
||||
return new ImageInfo(buf.getWidth(), buf.getHeight(), depth16 ? 16 : 8, alpha, gray, indexed);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.index.ItemVisitor;
|
||||
import com.vividsolutions.jts.index.strtree.STRtree;
|
||||
import java.io.IOException;
|
||||
import org.geotools.data.collection.SpatialIndexFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.feature.DefaultFeatureCollection;
|
||||
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.filter.Filter;
|
||||
|
||||
public class O2SpatialIndexFeatureCollection extends SpatialIndexFeatureCollection
|
||||
{
|
||||
public O2SpatialIndexFeatureCollection(SimpleFeatureCollection copy)
|
||||
throws IOException
|
||||
{
|
||||
super((SimpleFeatureType)copy.getSchema());
|
||||
addAll(copy);
|
||||
}
|
||||
|
||||
public SimpleFeatureCollection subCollection(final Filter filter)
|
||||
{
|
||||
final DefaultFeatureCollection collection = new DefaultFeatureCollection("MemoryFeatureCollection", this.schema);
|
||||
|
||||
Envelope bounds = (Envelope)filter.accept(ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
Envelope searchEnv;
|
||||
if ((bounds == null) || (bounds.isNull()))
|
||||
searchEnv = new Envelope((-1.0D / 0.0D), (1.0D / 0.0D), (-1.0D / 0.0D), (1.0D / 0.0D));
|
||||
else {
|
||||
searchEnv = bounds;
|
||||
}
|
||||
|
||||
this.index.query(searchEnv, new ItemVisitor() {
|
||||
public void visitItem(Object item) {
|
||||
SimpleFeature feature = (SimpleFeature)item;
|
||||
if (filter.evaluate(feature))
|
||||
collection.add(feature);
|
||||
}
|
||||
});
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
|
||||
public abstract interface O2SqlDialect
|
||||
{
|
||||
public abstract String getDbType();
|
||||
|
||||
public abstract List<ReferencedEnvelope> getInternalBounds(String paramString, SimpleFeatureType paramSimpleFeatureType, Connection paramConnection);
|
||||
}
|
||||
|
|
@ -1,272 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import org.geotools.styling.ChannelSelection;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ContrastEnhancement;
|
||||
import org.geotools.styling.Description;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.Fill;
|
||||
import org.geotools.styling.Font;
|
||||
import org.geotools.styling.Graphic;
|
||||
import org.geotools.styling.Halo;
|
||||
import org.geotools.styling.LabelPlacement;
|
||||
import org.geotools.styling.LineSymbolizer;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
import org.geotools.styling.RasterSymbolizer;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.ShadedRelief;
|
||||
import org.geotools.styling.Stroke;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleFactoryImpl;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
import org.geotools.styling.TextSymbolizer2;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class O2StyleFactory extends StyleFactoryImpl
|
||||
{
|
||||
public StyledLayerDescriptor createStyledLayerDescriptor()
|
||||
{
|
||||
StyledLayerDescriptor sld = super.createStyledLayerDescriptor();
|
||||
|
||||
sld.setName("");
|
||||
sld.setTitle("");
|
||||
sld.setAbstract("");
|
||||
|
||||
return sld;
|
||||
}
|
||||
|
||||
public UserLayer createUserLayer()
|
||||
{
|
||||
UserLayer layer = super.createUserLayer();
|
||||
|
||||
layer.setName("");
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
public NamedLayer createNamedLayer()
|
||||
{
|
||||
NamedLayer layer = super.createNamedLayer();
|
||||
|
||||
layer.setName("");
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
public NamedStyle createNamedStyle()
|
||||
{
|
||||
NamedStyle style = super.createNamedStyle();
|
||||
|
||||
style.setName("");
|
||||
if (style.getDescription() != null) {
|
||||
style.getDescription().setTitle("");
|
||||
style.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
public Style createStyle()
|
||||
{
|
||||
Style style = super.createStyle();
|
||||
|
||||
style.setName("");
|
||||
if (style.getDescription() != null) {
|
||||
style.getDescription().setTitle("");
|
||||
style.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
public FeatureTypeStyle createFeatureTypeStyle()
|
||||
{
|
||||
FeatureTypeStyle ftStyle = super.createFeatureTypeStyle();
|
||||
|
||||
ftStyle.setName("");
|
||||
if (ftStyle.getDescription() != null) {
|
||||
ftStyle.getDescription().setTitle("");
|
||||
ftStyle.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return ftStyle;
|
||||
}
|
||||
|
||||
public FeatureTypeStyle createFeatureTypeStyle(Rule[] rules)
|
||||
{
|
||||
FeatureTypeStyle ftStyle = super.createFeatureTypeStyle(rules);
|
||||
|
||||
ftStyle.setName("");
|
||||
if (ftStyle.getDescription() != null) {
|
||||
ftStyle.getDescription().setTitle("");
|
||||
ftStyle.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return ftStyle;
|
||||
}
|
||||
|
||||
public Rule createRule()
|
||||
{
|
||||
Rule rule = super.createRule();
|
||||
|
||||
rule.setName("");
|
||||
if (rule.getDescription() != null) {
|
||||
rule.getDescription().setTitle("");
|
||||
rule.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
public PointSymbolizer createPointSymbolizer()
|
||||
{
|
||||
PointSymbolizer symbol = super.createPointSymbolizer();
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PointSymbolizer createPointSymbolizer(Graphic graphic, String geometryPropertyName)
|
||||
{
|
||||
PointSymbolizer symbol = super.createPointSymbolizer(graphic, geometryPropertyName);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public LineSymbolizer createLineSymbolizer()
|
||||
{
|
||||
LineSymbolizer symbol = super.createLineSymbolizer();
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public LineSymbolizer createLineSymbolizer(Stroke stroke, String geometryPropertyName)
|
||||
{
|
||||
LineSymbolizer symbol = super.createLineSymbolizer(stroke, geometryPropertyName);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PolygonSymbolizer createPolygonSymbolizer()
|
||||
{
|
||||
PolygonSymbolizer symbol = super.createPolygonSymbolizer();
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PolygonSymbolizer createPolygonSymbolizer(Stroke stroke, Fill fill, String geometryPropertyName)
|
||||
{
|
||||
PolygonSymbolizer symbol = super.createPolygonSymbolizer(stroke, fill, geometryPropertyName);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer createTextSymbolizer()
|
||||
{
|
||||
TextSymbolizer symbol = super.createTextSymbolizer();
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer createTextSymbolizer(Fill fill, Font[] fonts, Halo halo, Expression label, LabelPlacement labelPlacement, String geometryPropertyName)
|
||||
{
|
||||
TextSymbolizer symbol = super.createTextSymbolizer(fill, fonts, halo, label, labelPlacement,
|
||||
geometryPropertyName);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer2 createTextSymbolizer(Fill fill, Font[] fonts, Halo halo, Expression label, LabelPlacement labelPlacement, String geometryPropertyName, Graphic graphic)
|
||||
{
|
||||
TextSymbolizer2 symbol = super.createTextSymbolizer(fill, fonts, halo, label, labelPlacement,
|
||||
geometryPropertyName, graphic);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public RasterSymbolizer createRasterSymbolizer()
|
||||
{
|
||||
RasterSymbolizer symbol = super.createRasterSymbolizer();
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public RasterSymbolizer createRasterSymbolizer(String geometryPropertyName, Expression opacity, ChannelSelection channel, Expression overlap, ColorMap colorMap, ContrastEnhancement cenhancement, ShadedRelief relief, Symbolizer outline)
|
||||
{
|
||||
RasterSymbolizer symbol = super.createRasterSymbolizer(geometryPropertyName, opacity, channel,
|
||||
overlap, colorMap, cenhancement, relief, outline);
|
||||
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,439 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.geotools.data.Transaction;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class O2WpsLayerSet
|
||||
{
|
||||
private HashMap<String, Layer> layerStore = new HashMap();
|
||||
private final String tableName;
|
||||
|
||||
public O2WpsLayerSet(String tableName)
|
||||
{
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public void addLayer(Layer layer, boolean overWrite)
|
||||
throws Exception
|
||||
{
|
||||
addLayer(this.tableName, layer);
|
||||
}
|
||||
|
||||
public void addLayer(String tblName, Layer layer)
|
||||
throws Exception
|
||||
{
|
||||
if ((layer == null) || (ServerUtil.isNullString(layer.getName()))) {
|
||||
throw new IllegalArgumentException("Layer object or Layer name is NULL.");
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(tblName)) {
|
||||
throw new IllegalArgumentException("Meta table name is NULL.");
|
||||
}
|
||||
|
||||
String layerName = layer.getName();
|
||||
layerName = layerName.trim().toUpperCase();
|
||||
|
||||
boolean bDone = isExistLayer(tblName, layerName);
|
||||
if (bDone) {
|
||||
throw new IllegalArgumentException("Layer [" + layerName + "] is already exist.");
|
||||
}
|
||||
|
||||
String layerType = "FEA";
|
||||
if (layer.getLayerType() == LayerFactory.LayerType.O2WPSCOV) {
|
||||
layerType = "RAS";
|
||||
}
|
||||
String layerSource = layer.getSourceName();
|
||||
String sourcePath = layer.getSourcePath();
|
||||
String sourceType = layer.getSourceType();
|
||||
String refSrid = CRS.toSRS(layer.getCRS());
|
||||
String authorId = layer.getAuthorId();
|
||||
java.util.Date regDate = layer.getLastUpdate();
|
||||
String hashTag = layer.getHashTag();
|
||||
String layerDesc = layer.getAbstract();
|
||||
|
||||
JDBCDataStore ds = WpsVecStoreMngr.getDataStore();
|
||||
Connection cx = null;
|
||||
PreparedStatement pst = null;
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("INSERT INTO ");
|
||||
sql.append(tblName);
|
||||
sql.append(" (");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERTYPE.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERSRC.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_SRCPATH.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_SRCTYPE.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_REFSRID.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_AUTHORID.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_REGDATE.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_HASHTAG.toString()).append(",");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_DESC.toString()).append(" ");
|
||||
sql.append(")");
|
||||
sql.append(" VALUES ");
|
||||
sql.append("(?,?,?,?,?,?,?,?,?,?)");
|
||||
try
|
||||
{
|
||||
cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||
pst = cx.prepareStatement(sql.toString());
|
||||
pst.setFetchSize(1);
|
||||
|
||||
pst.setString(1, layerName);
|
||||
pst.setString(2, layerType);
|
||||
pst.setString(3, layerSource);
|
||||
pst.setString(4, sourcePath);
|
||||
pst.setString(5, sourceType);
|
||||
pst.setString(6, refSrid);
|
||||
pst.setString(7, authorId);
|
||||
pst.setTimestamp(8, new Timestamp(regDate.getTime()));
|
||||
pst.setString(9, hashTag);
|
||||
pst.setString(10, layerDesc);
|
||||
|
||||
pst.executeUpdate();
|
||||
|
||||
if (!tblName.equalsIgnoreCase(WpsVecStoreMngr.O2WpsMetaTableType.SHARELYRINFO_TBL.getName()))
|
||||
this.layerStore.put(layerName, layer);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Error sql execute : " + e);
|
||||
}
|
||||
finally {
|
||||
if (pst != null) {
|
||||
pst.close();
|
||||
}
|
||||
if (cx != null)
|
||||
cx.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void addLayers(ArrayList<Layer> layers, boolean overWrite)
|
||||
throws Exception
|
||||
{
|
||||
if (layers == null) {
|
||||
throw new IllegalArgumentException("Layers object is NULL.");
|
||||
}
|
||||
|
||||
for (Layer layer : layers)
|
||||
{
|
||||
if ((overWrite) || (!this.layerStore.containsKey(layer.getName())))
|
||||
{
|
||||
this.layerStore.put(layer.getName(), layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExistLayer(String storeTbl, String name)
|
||||
throws Exception, SQLException, IOException
|
||||
{
|
||||
boolean bDone = this.layerStore.containsKey(name);
|
||||
if (bDone) return bDone;
|
||||
|
||||
JDBCDataStore ds = WpsVecStoreMngr.getDataStore();
|
||||
Connection cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||
Statement st = cx.createStatement();
|
||||
try
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT COUNT(*) FROM ");
|
||||
sql.append(storeTbl);
|
||||
sql.append(" WHERE ");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString()).append("=");
|
||||
sql.append("'");
|
||||
sql.append(name.trim().toUpperCase()).append("'");
|
||||
|
||||
ResultSet rs = st.executeQuery(sql.toString());
|
||||
try
|
||||
{
|
||||
rs.next();
|
||||
Double cnt = Double.valueOf(rs.getDouble(1));
|
||||
if (cnt == null) {
|
||||
bDone = false;
|
||||
}
|
||||
else if (cnt.doubleValue() > 0.0D) bDone = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Error sql execute : " + e);
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
cx.close();
|
||||
st.close();
|
||||
}
|
||||
|
||||
return bDone;
|
||||
}
|
||||
|
||||
public Layer getLayer(String name)
|
||||
throws Exception, SQLException, IOException
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
throw new IllegalArgumentException("Layer Name [" + name + "] is NULL.");
|
||||
}
|
||||
|
||||
name = name.trim().toUpperCase();
|
||||
|
||||
Layer lyr = (Layer)this.layerStore.get(name);
|
||||
if (lyr != null) {
|
||||
return lyr;
|
||||
}
|
||||
|
||||
return getLayer(this.tableName, name);
|
||||
}
|
||||
|
||||
public Layer getLayer(String tblName, String name)
|
||||
throws Exception, SQLException, IOException
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
throw new IllegalArgumentException("Layer Name [" + name + "] is NULL.");
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(tblName)) {
|
||||
throw new IllegalArgumentException("Table Name [" + tblName + "] is NULL.");
|
||||
}
|
||||
|
||||
tblName = tblName.trim().toUpperCase();
|
||||
name = name.trim().toUpperCase();
|
||||
|
||||
JDBCDataStore ds = WpsVecStoreMngr.getDataStore();
|
||||
Connection cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||
Statement st = cx.createStatement();
|
||||
try
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT * FROM ");
|
||||
sql.append(tblName);
|
||||
sql.append(" WHERE ");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString()).append("=");
|
||||
sql.append("'");
|
||||
sql.append(name).append("'");
|
||||
|
||||
ResultSet rs = st.executeQuery(sql.toString());
|
||||
|
||||
if (rs == null) {
|
||||
throw new Exception("Error sql execute : resultSet is NULL.");
|
||||
}
|
||||
try
|
||||
{
|
||||
boolean bDone = rs.next();
|
||||
if (!bDone) {
|
||||
throw new Exception("layer is not exist.");
|
||||
}
|
||||
|
||||
String layerName = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString());
|
||||
String layerType = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERTYPE.toString());
|
||||
String layerSource = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERSRC.toString());
|
||||
String sourcePath = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_SRCPATH.toString());
|
||||
String sourceType = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_SRCTYPE.toString());
|
||||
String refSrid = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_REFSRID.toString());
|
||||
String authorId = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_AUTHORID.toString());
|
||||
String hashTag = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_HASHTAG.toString());
|
||||
String layerDesc = rs.getString(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_DESC.toString());
|
||||
|
||||
java.util.Date regDate = null;
|
||||
try {
|
||||
regDate = rs.getTimestamp(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_REGDATE.toString());
|
||||
} catch (Exception de) {
|
||||
try {
|
||||
Timestamp stamp = rs.getTimestamp(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_REGDATE.toString());
|
||||
regDate = new java.sql.Date(stamp.getTime());
|
||||
} catch (Exception se) {
|
||||
regDate = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AVList params = new AVList();
|
||||
params.setValue("conf.service.map.name", ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", layerName);
|
||||
|
||||
if (layerType.equalsIgnoreCase("FEA"))
|
||||
params.setValue("conf.service.ref.server", LayerFactory.LayerType.O2WPSVEC.getType());
|
||||
else {
|
||||
params.setValue("conf.service.ref.server", LayerFactory.LayerType.O2WPSCOV.getType());
|
||||
}
|
||||
|
||||
CoordinateReferenceSystem crs = CRS.decode(refSrid);
|
||||
params.setValue("conf.service.ref.source", layerSource);
|
||||
params.setValue("conf.service.o2wps.source.path", sourcePath);
|
||||
params.setValue("conf.service.ref.crs", crs);
|
||||
params.setValue("conf.service.sld", null);
|
||||
params.setValue("conf.service.use.cache", Boolean.valueOf(false));
|
||||
params.setValue("conf.service.last.update", regDate);
|
||||
params.setValue("conf.service.description", layerDesc);
|
||||
params.setValue("conf.service.o2wps.source.type", sourceType);
|
||||
params.setValue("conf.service.o2wps.author.id", authorId);
|
||||
params.setValue("conf.service.o2wps.hashtag", hashTag);
|
||||
|
||||
Layer layer = null;
|
||||
if (layerType.equalsIgnoreCase("FEA"))
|
||||
layer = LayerFactory.createLayer(LayerFactory.LayerType.O2WPSVEC, params);
|
||||
else {
|
||||
layer = LayerFactory.createLayer(LayerFactory.LayerType.O2WPSCOV, params);
|
||||
}
|
||||
|
||||
return layer;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new Exception("Error sql execute : " + e);
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
cx.close();
|
||||
st.close();
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers()
|
||||
{
|
||||
return new ArrayList(this.layerStore.values());
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers(LayerFactory.LayerType type)
|
||||
{
|
||||
ArrayList layers = new ArrayList();
|
||||
|
||||
for (Layer layer : this.layerStore.values())
|
||||
{
|
||||
if (layer.getLayerType() == type) {
|
||||
layers.add(layer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
public void removeLayer(String tblName, String name)
|
||||
throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(name)) {
|
||||
throw new IllegalArgumentException("Layer Name [" + name + "] is NULL.");
|
||||
}
|
||||
|
||||
if (ServerUtil.isNullString(tblName)) {
|
||||
throw new IllegalArgumentException("Table Name [" + tblName + "] is NULL.");
|
||||
}
|
||||
|
||||
tblName = tblName.trim().toUpperCase();
|
||||
name = name.trim().toUpperCase();
|
||||
|
||||
JDBCDataStore ds = WpsVecStoreMngr.getDataStore();
|
||||
Connection cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||
Statement st = cx.createStatement();
|
||||
st.setFetchSize(1);
|
||||
try
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("DELETE FROM ");
|
||||
sql.append(tblName);
|
||||
sql.append(" WHERE ");
|
||||
sql.append(WpsVecStoreMngr.O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString()).append("=");
|
||||
sql.append("'");
|
||||
sql.append(name).append("'");
|
||||
|
||||
st.executeUpdate(sql.toString());
|
||||
|
||||
if (!tblName.equalsIgnoreCase(WpsVecStoreMngr.O2WpsMetaTableType.SHARELYRINFO_TBL.getName()))
|
||||
this.layerStore.remove(name);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
cx.close();
|
||||
st.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Layer removeLayer(String name)
|
||||
throws Exception
|
||||
{
|
||||
Layer layer = getLayer(name);
|
||||
if (layer != null) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
}
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
||||
throws Exception
|
||||
{
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName)
|
||||
throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(serverName)) {
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
}
|
||||
serverName = serverName.trim();
|
||||
|
||||
ArrayList resultList = new ArrayList();
|
||||
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName, String sourceName) throws Exception
|
||||
{
|
||||
if (ServerUtil.isNullString(serverName)) {
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
}
|
||||
serverName = serverName.trim();
|
||||
|
||||
if (ServerUtil.isNullString(sourceName)) {
|
||||
throw new IllegalArgumentException("Source Name [" + sourceName + "] is NULL.");
|
||||
}
|
||||
sourceName = sourceName.trim();
|
||||
|
||||
ArrayList resultList = new ArrayList();
|
||||
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
|
||||
for (Layer layer : layers) {
|
||||
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
||||
(layer.getSourceName().equalsIgnoreCase(sourceName))) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class OWSConstants
|
||||
{
|
||||
public static final List<String> wfsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeFeatureType", "GetFeature", "GetGmlObject", "Transaction", "LockFeature" });
|
||||
public static final List<String> wfsRequests100 = Arrays.asList(new String[] { "GetCapabilities", "DescribeFeatureType", "GetFeature", "Transaction", "LockFeature" });
|
||||
public static final List<String> wmsRequests = Arrays.asList(new String[] { "GetCapabilities", "GetFeatureInfo", "GetMap", "GetLegendGraphic" });
|
||||
public static final List<String> wcsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeCoverage", "GetCoverage" });
|
||||
public static final List<String> wpsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeProcess", "Execute" });
|
||||
public static final List<String> wmtsRequests = Arrays.asList(new String[] { "GetCapabilities", "GetTile" });
|
||||
|
||||
public static final List<String> wfsVersions = Arrays.asList(new String[] { "1.1.0", "1.0.0" });
|
||||
public static final List<String> wmsVersions = Arrays.asList(new String[] { "1.3.0" });
|
||||
public static final List<String> wcsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||
public static final List<String> wpsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||
public static final List<String> wmtsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||
|
||||
public static final List<String> outputFormat = Arrays.asList(new String[] { "text/xml", "text/xml; subtype=gml/2.1.2", "text/xml; subtype=gml/3.1.1", "application/json" });
|
||||
public static final List<String> outputFormat100 = Arrays.asList(new String[] { "XMLSCHEMA", "GML2", "GML3", "application/json" });
|
||||
public static final List<String> featureInfooutputFormat = Arrays.asList(new String[] { "text/xml", "application/vnd.ogc.gml", "application/vnd.ogc.gml/3.1.1", "application/json" });
|
||||
public static final List<String> imageOutputFormat = Arrays.asList(new String[] { "image/png", "image/jpeg", "image/jpg" });
|
||||
public static final List<String> wmtsOutputFormat = Arrays.asList(new String[] { "image/png", "image/jpeg", "image/jpg" });
|
||||
public static final List<String> wcsFormats = Arrays.asList(new String[] { "GeoTIFF", "O2FGRID", "O2IGRID" });
|
||||
public static final String wfsDefaultVersion = "1.1.0";
|
||||
public static final String wfsDefaultOutputformat = "text/xml; subtype=gml/3.1.1";
|
||||
public static final String wfsDefaultOutputformatGetFeature100 = "GML2";
|
||||
public static final String wfsDefaultOutputformatDescribeFeatureType100 = "XMLSCHEMA";
|
||||
public static final int wfsLockFeatureDefaultExpiry = 5;
|
||||
public static final String wmsDefaultVersion = "1.3.0";
|
||||
public static final String wmsGetMapDefaultTransparent = "false";
|
||||
public static final String wmsGetMapDefaultBGcolor = "0xFFFFFF";
|
||||
public static final String wmsGetLegendGraphicDefaultWidth = "20";
|
||||
public static final String wmsGetLegendGraphicDefaultHeight = "20";
|
||||
public static final String wpsDefaultVersion = "1.0.0";
|
||||
public static final String wmtsDefaultVersion = "1.0.0";
|
||||
public static final String wcsDefaultVersion = "1.0.0";
|
||||
public static final List<String> wpsProcessList = Arrays.asList(new String[] { "Buffer", "Contains", "Intersection", "Intersects" });
|
||||
public static final List<String> upisProcessList = Arrays.asList(new String[] { "Sync", "VA_Export", "VA_AreaNCount" });
|
||||
public static String wpsRepositoryDir = null;
|
||||
|
||||
public static boolean isContains(List<String> list, String target)
|
||||
{
|
||||
Iterator itr = list.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
String listEle = (String)itr.next();
|
||||
if (listEle.equalsIgnoreCase(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
|
||||
public class OWSServiceException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 2014070913143234L;
|
||||
public static final String MissingParameterValue = "MissingParameterValue";
|
||||
public static final String OperationNotSupported = "OperationNotSupported";
|
||||
public static final String InvalidParameterValue = "InvalidParameterValue";
|
||||
public static final String VersionNegotiationFailed = "VersionNegotiationFailed";
|
||||
public static final String InvalidFormat = "InvalidFormat";
|
||||
public static final String InvalidCRS = "InvalidCRS";
|
||||
public static final String LayerNotDefined = "LayerNotDefined";
|
||||
public static final String StyleNotDefined = "StyleNotDefined";
|
||||
public static final String LayerNotQueryable = "LayerNotQueryable";
|
||||
public static final String InvalidPoint = "InvalidPoint";
|
||||
private String exceptionCode = "OperationNotSupported";
|
||||
private String locator = null;
|
||||
|
||||
public OWSServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public OWSServiceException(String message, String exceptionCode) {
|
||||
super(message);
|
||||
|
||||
this.exceptionCode = exceptionCode;
|
||||
this.locator = null;
|
||||
}
|
||||
|
||||
public OWSServiceException(String message, String exceptionCode, String locator) {
|
||||
super(message);
|
||||
|
||||
this.exceptionCode = exceptionCode;
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
public Document getDocument()
|
||||
{
|
||||
NamespaceSupport support = new NamespaceSupport();
|
||||
|
||||
support.declarePrefix("ogc", "http://www.opengis.net/ogc");
|
||||
support.declarePrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||
support.declarePrefix("schemaLocation", "http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd");
|
||||
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
docFactory.setNamespaceAware(true);
|
||||
|
||||
DocumentBuilder docBuilder = null;
|
||||
try
|
||||
{
|
||||
docBuilder = docFactory.newDocumentBuilder();
|
||||
}
|
||||
catch (ParserConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
LogMngr.getInstance().reqInfo("[SERVICE]", "Write Exception Error : " + e.getMessage());
|
||||
}
|
||||
|
||||
Document doc = docBuilder.newDocument();
|
||||
|
||||
Element rootElement = doc.createElementNS(support.getURI("ogc"), "ServiceExceptionReport");
|
||||
|
||||
rootElement.setAttribute("xmlns", support.getURI("ogc"));
|
||||
rootElement.setAttribute("version", "1.3.0");
|
||||
|
||||
String xmlnsURI = "http://www.w3.org/2000/xmlns/";
|
||||
rootElement.setAttributeNS(xmlnsURI, "xmlns:xsi", support.getURI("xsi"));
|
||||
rootElement.setAttributeNS(support.getURI("xsi"), "xsi:schemaLocation", support.getURI("schemaLocation"));
|
||||
|
||||
doc.appendChild(rootElement);
|
||||
|
||||
org.w3c.dom.Element serviceExceptionElement = doc.createElementNS(support.getURI("ogc"), "ServiceException");
|
||||
|
||||
if (this.exceptionCode != null) {
|
||||
serviceExceptionElement.setAttribute("code", this.exceptionCode);
|
||||
}
|
||||
|
||||
if (this.locator != null) {
|
||||
serviceExceptionElement.setAttribute("locator", this.locator);
|
||||
}
|
||||
|
||||
setElementTextContent(serviceExceptionElement,getMessage());
|
||||
|
||||
rootElement.appendChild(serviceExceptionElement);
|
||||
|
||||
if (ServerContext.isUseNSPrefix()) {
|
||||
rootElement.setPrefix("ogc");
|
||||
serviceExceptionElement.setPrefix("ogc");
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
// Added by thkim
|
||||
public static void setElementTextContent(Element element, String text) {
|
||||
// 기존 자식 노드들을 모두 제거
|
||||
Node child;
|
||||
while ((child = element.getFirstChild()) != null) {
|
||||
element.removeChild(child);
|
||||
}
|
||||
|
||||
// 새로운 텍스트 노드 생성 및 추가
|
||||
Text textNode = element.getOwnerDocument().createTextNode(text);
|
||||
element.appendChild(textNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,538 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryCollection;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.LinearRing;
|
||||
import com.vividsolutions.jts.geom.MultiLineString;
|
||||
import com.vividsolutions.jts.geom.MultiPoint;
|
||||
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Wrapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import oracle.jdbc.OracleConnection;
|
||||
import oracle.sql.STRUCT;
|
||||
import org.geotools.data.jdbc.datasource.DataSourceFinder;
|
||||
import org.geotools.data.jdbc.datasource.UnWrapper;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||
import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class OracleDialect extends PreparedStatementSQLDialect implements O2SqlDialect {
|
||||
public final String ORACLE_NULL_SRID_KEY = "OracleNullSrid";
|
||||
|
||||
final String serverName;
|
||||
|
||||
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
||||
|
||||
private HashMap<String, Integer> sridStore = new HashMap<String, Integer>();
|
||||
|
||||
UnWrapper uw;
|
||||
|
||||
public OracleDialect(String name, JDBCDataStore dataStore) {
|
||||
super(dataStore);
|
||||
this.serverName = name;
|
||||
}
|
||||
|
||||
public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||
int TABLE_NAME = 3;
|
||||
int COLUMN_NAME = 4;
|
||||
int TYPE_NAME = 6;
|
||||
String typeName = columnMetaData.getString(6).toUpperCase();
|
||||
if (typeName.equals("SDO_GEOMETRY")) {
|
||||
Class<Geometry> gemetry = lookupGeometryType(columnMetaData, cx);
|
||||
if (gemetry == null)
|
||||
gemetry = Geometry.class;
|
||||
return gemetry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
||||
String tableName = columnMetaData.getString("TABLE_NAME");
|
||||
String columnName = columnMetaData.getString("COLUMN_NAME");
|
||||
lookupDBSrid(cx, tableName, columnName);
|
||||
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
||||
if (schemaName == null || schemaName.equals("")) {
|
||||
schemaName = "";
|
||||
} else {
|
||||
schemaName = String.valueOf(schemaName) + ".";
|
||||
}
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next())
|
||||
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
||||
} catch (Exception exception) {
|
||||
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT ");
|
||||
sql.append(columnName);
|
||||
sql.append(" FROM ");
|
||||
sql.append(schemaName).append(tableName);
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
STRUCT st = (STRUCT)rs.getObject(1);
|
||||
Geometry geom = getGeometryFromStruct(st, (GeometryFactory)null, cx);
|
||||
return O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) {
|
||||
super.registerSqlTypeNameToClassMappings(mappings);
|
||||
mappings.put("SDO_GEOMETRY", Geometry.class);
|
||||
mappings.put("MDSYS.SDO_GEOMETRY", Geometry.class);
|
||||
mappings.put("CHAR", String.class);
|
||||
mappings.put("NCHAR", String.class);
|
||||
mappings.put("NVARCHAR", String.class);
|
||||
mappings.put("NVARCHAR2", String.class);
|
||||
}
|
||||
|
||||
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings) {
|
||||
super.registerSqlTypeToClassMappings(mappings);
|
||||
}
|
||||
|
||||
private void lookupDBSrid(Connection cx, String tableName, String columnName) {
|
||||
LogMngr.getInstance().logDebug("[DB]",
|
||||
"Lookup dbms srid value for [" + tableName + "/" + columnName + "]");
|
||||
String sridKey = String.valueOf(tableName.trim().toUpperCase()) + "_" + columnName.trim().toUpperCase();
|
||||
if (this.sridStore.get(sridKey) != null)
|
||||
return;
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT SRID FROM USER_SDO_GEOM_METADATA");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName).append("'");
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
Integer srid = Integer.valueOf(rs.getInt(1));
|
||||
this.sridStore.put(sridKey, srid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"Fail to lookup dbms srid value for [" + tableName + "/" + columnName + "] :: " + e);
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getDBSrid(String tableName, String columnName) {
|
||||
String sridKey = String.valueOf(tableName.trim().toUpperCase()) + "_" + columnName.trim().toUpperCase();
|
||||
return this.sridStore.get(sridKey);
|
||||
}
|
||||
|
||||
private Geometry getGeometryFromStruct(STRUCT struct, GeometryFactory factory, Connection cx) throws SQLException {
|
||||
if (struct == null)
|
||||
return null;
|
||||
OracleConnection ocx = unwrapConnection(cx);
|
||||
GeometryConverter converter =
|
||||
(factory != null) ? new GeometryConverter(ocx, factory) : new GeometryConverter(ocx);
|
||||
return converter.asGeometry(struct);
|
||||
}
|
||||
|
||||
private STRUCT getStructFromGeometry(Geometry geometry, int srid, Connection cx) throws SQLException {
|
||||
if (geometry == null)
|
||||
return null;
|
||||
OracleConnection ocx = unwrapConnection(cx);
|
||||
GeometryConverter converter = new GeometryConverter(ocx);
|
||||
return converter.toSDO(geometry, srid);
|
||||
}
|
||||
|
||||
private int getDimensionsFromGeometry(Geometry geom) {
|
||||
if (geom != null) {
|
||||
Coordinate coord = geom.getCoordinate();
|
||||
if (coord != null) {
|
||||
if (Double.isNaN(coord.x))
|
||||
return 0;
|
||||
if (Double.isNaN(coord.y))
|
||||
return 1;
|
||||
if (Double.isNaN(coord.z))
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private OracleConnection unwrapConnection(Connection cx) throws SQLException {
|
||||
if (cx == null)
|
||||
return null;
|
||||
if (cx instanceof OracleConnection)
|
||||
return (OracleConnection)cx;
|
||||
try {
|
||||
if (cx instanceof Wrapper && this.uw != null)
|
||||
try {
|
||||
Wrapper w = cx;
|
||||
if (w.isWrapperFor(OracleConnection.class))
|
||||
return w.<OracleConnection>unwrap(OracleConnection.class);
|
||||
} catch (Throwable t) {
|
||||
LOGGER.log(Level.FINE, "Failed to unwrap connection using java 6 facilities", t);
|
||||
}
|
||||
if (this.uw == null)
|
||||
this.uw = DataSourceFinder.getUnWrapper(cx);
|
||||
if (this.uw != null) {
|
||||
Connection uwcx = this.uw.unwrap(cx);
|
||||
if (uwcx != null && uwcx instanceof OracleConnection)
|
||||
return (OracleConnection)uwcx;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw (SQLException)(new SQLException(
|
||||
"Could not obtain native oracle connection.")).initCause(e);
|
||||
}
|
||||
throw new SQLException("Could not obtain native oracle connection for " + cx.getClass());
|
||||
}
|
||||
|
||||
private Geometry convertGeometry(Geometry geom, GeometryDescriptor descriptor, GeometryFactory factory) {
|
||||
if (geom == null)
|
||||
return null;
|
||||
Class targetClazz = descriptor.getType().getBinding();
|
||||
if (targetClazz.equals(MultiPolygon.class) && geom instanceof Polygon)
|
||||
return (Geometry)factory.createMultiPolygon(new Polygon[] { (Polygon)geom });
|
||||
if (targetClazz.equals(MultiPoint.class) && geom instanceof Point)
|
||||
return (Geometry)factory.createMultiPoint(new Point[] { (Point)geom });
|
||||
if (targetClazz.equals(MultiLineString.class) && geom instanceof LineString)
|
||||
return (Geometry)factory.createMultiLineString(new LineString[] { (LineString)geom });
|
||||
if (targetClazz.equals(GeometryCollection.class))
|
||||
return (Geometry)factory.createGeometryCollection(new Geometry[] { geom });
|
||||
return geom;
|
||||
}
|
||||
|
||||
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx) throws SQLException {
|
||||
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
||||
if (schemaName == null || schemaName.equals("")) {
|
||||
schemaName = "";
|
||||
} else {
|
||||
schemaName = String.valueOf(schemaName) + ".";
|
||||
}
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("SELECT REF_SRID FROM ");
|
||||
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
||||
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
||||
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
||||
rs = stat.executeQuery(sb.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
Object obj = rs.getObject(1);
|
||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" +
|
||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT SRID FROM ");
|
||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
Object obj = rs.getObject(1);
|
||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" +
|
||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
||||
return this.DEFAULT_CRS;
|
||||
}
|
||||
|
||||
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException {
|
||||
try {
|
||||
return CRSMngr.getLayerCRS(srid, true);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLimitOffsetSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
|
||||
if (offset == 0) {
|
||||
sql.insert(0, "SELECT * FROM (");
|
||||
sql.append(") WHERE ROWNUM <= " + limit);
|
||||
} else {
|
||||
long max = (limit == Integer.MAX_VALUE) ? Long.MAX_VALUE : (limit + offset);
|
||||
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||
sql.append("WHERE RNUM > " + offset);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException, IOException {
|
||||
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
String schema = "";
|
||||
if (schemaName == null || schemaName.equals("")) {
|
||||
schema = "";
|
||||
} else {
|
||||
schema = String.valueOf(schemaName) + ".";
|
||||
}
|
||||
schema = schema.toUpperCase();
|
||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||
if (att instanceof GeometryDescriptor) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
||||
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
||||
sql.append(" WHERE");
|
||||
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
||||
sql.append(" AND");
|
||||
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||
double x1 = rs.getDouble(1);
|
||||
double x2 = rs.getDouble(2);
|
||||
double y1 = rs.getDouble(3);
|
||||
double y2 = rs.getDouble(4);
|
||||
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
} catch (SQLException e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
||||
return getInternalBounds(schemaName, featureType, cx);
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx) {
|
||||
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||
Statement stat = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stat = cx.createStatement();
|
||||
stat.setFetchSize(1);
|
||||
if (schemaName == null || schemaName.equals("")) {
|
||||
schemaName = "";
|
||||
} else {
|
||||
schemaName = String.valueOf(schemaName) + ".";
|
||||
}
|
||||
schemaName = schemaName.toUpperCase();
|
||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||
if (att instanceof GeometryDescriptor) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT ");
|
||||
encodeGeometryEnvelope((String)null, att.getLocalName().toUpperCase(), sql);
|
||||
sql.append(" FROM ");
|
||||
sql.append(schemaName).append(featureType.getTypeName().toUpperCase());
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
rs = stat.executeQuery(sql.toString());
|
||||
if (rs != null && rs.next()) {
|
||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||
Envelope env = decodeGeometryEnvelope(rs, 1, cx);
|
||||
resultList.add(ReferencedEnvelope.create(env, crs));
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
||||
} finally {
|
||||
this.dataStore.closeSafe(rs);
|
||||
this.dataStore.closeSafe(stat);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql) {
|
||||
sql.append("SDO_AGGR_MBR(");
|
||||
encodeColumnName((String)null, geometryColumn, sql);
|
||||
sql.append(")");
|
||||
}
|
||||
|
||||
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException {
|
||||
try {
|
||||
STRUCT st = (STRUCT)rs.getObject(column);
|
||||
Geometry geom = getGeometryFromStruct(st, (GeometryFactory)null, cx);
|
||||
return geom.getEnvelopeInternal();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[DB]", "Fail to decode GeometryEnvelope : " + e.getMessage());
|
||||
return new Envelope();
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql) {
|
||||
super.prepareGeometryValue(g, dimension, srid, binding, sql);
|
||||
}
|
||||
|
||||
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException {
|
||||
if (g != null) {
|
||||
LineString lineString = null;
|
||||
if (g instanceof LinearRing)
|
||||
lineString = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||
if (isNullSridGeometry((Geometry)lineString))
|
||||
srid = 0;
|
||||
STRUCT struct = getStructFromGeometry((Geometry)lineString, srid, ps.getConnection());
|
||||
ps.setObject(column, struct);
|
||||
} else {
|
||||
ps.setNull(column, 2002, "MDSYS.SDO_GEOMETRY");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNullSridGeometry(Geometry g) {
|
||||
try {
|
||||
String userData = (String)g.getUserData();
|
||||
if (userData.equalsIgnoreCase("OracleNullSrid"))
|
||||
return true;
|
||||
} catch (Exception exception) {}
|
||||
for (int i = 0; i < g.getNumGeometries(); i++) {
|
||||
Geometry innerGeom = g.getGeometryN(i);
|
||||
try {
|
||||
String userData = (String)innerGeom.getUserData();
|
||||
if (userData.equalsIgnoreCase("OracleNullSrid"))
|
||||
return true;
|
||||
} catch (Exception exception) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, Hints hints, StringBuffer sql) {
|
||||
String sqlStr = "";
|
||||
if (prefix != null)
|
||||
sqlStr = String.valueOf(prefix) + ".";
|
||||
sqlStr = String.valueOf(sqlStr) + gatt.getLocalName();
|
||||
sql.append(sqlStr);
|
||||
}
|
||||
|
||||
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx) throws IOException, SQLException {
|
||||
STRUCT struct = (STRUCT)rs.getObject(column);
|
||||
Geometry geom = getGeometryFromStruct(struct, factory, cx);
|
||||
geom = convertGeometry(geom, descriptor, factory);
|
||||
return geom;
|
||||
}
|
||||
|
||||
public PreparedFilterToSQL createPreparedFilterToSQL() {
|
||||
return new OracleFilterToSQL(this);
|
||||
}
|
||||
|
||||
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||
select.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||
delete.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||
insert.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||
update.setFetchSize(this.dataStore.getFetchSize());
|
||||
}
|
||||
|
||||
public void encodeTableName(String raw, StringBuffer sql) {
|
||||
raw = raw.toUpperCase();
|
||||
if (raw.length() > 30)
|
||||
raw = raw.substring(0, 30);
|
||||
sql.append(raw);
|
||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||
}
|
||||
|
||||
public void encodeColumnName(String prefix, String raw, StringBuffer sql) {
|
||||
if (prefix != null) {
|
||||
prefix = prefix.toUpperCase();
|
||||
if (prefix.length() > 30)
|
||||
prefix = prefix.substring(0, 30);
|
||||
sql.append(prefix).append(".");
|
||||
}
|
||||
raw = raw.toUpperCase();
|
||||
if (raw.length() > 30)
|
||||
raw = raw.substring(0, 30);
|
||||
sql.append(raw);
|
||||
}
|
||||
|
||||
public String getNameEscape() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getGeometryTypeName(Integer type) {
|
||||
return "MDSYS.SDO_GEOMETRY";
|
||||
}
|
||||
|
||||
public boolean lookupGeneratedValuesPostInsert() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return O2DSFactory.DBMSType.ORACLE.getTypeName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.geotools.data.jdbc.FilterToSQL.FieldEncoder;
|
||||
import org.geotools.filter.FilterCapabilities;
|
||||
import org.geotools.geometry.jts.JTS;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.jdbc.JoinPropertyName;
|
||||
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||
import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||
import org.geotools.jdbc.SQLDialect;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.filter.expression.Literal;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
import org.opengis.filter.spatial.BBOX;
|
||||
import org.opengis.filter.spatial.BinarySpatialOperator;
|
||||
|
||||
public class OracleFilterToSQL extends PreparedFilterToSQL
|
||||
{
|
||||
private OracleDialect dsDialect;
|
||||
|
||||
public OracleFilterToSQL(OracleDialect dialect)
|
||||
{
|
||||
this.dsDialect = dialect;
|
||||
}
|
||||
|
||||
protected FilterCapabilities createFilterCapabilities()
|
||||
{
|
||||
FilterCapabilities caps = new FilterCapabilities();
|
||||
caps.addAll(SQLDialect.BASE_DBMS_CAPABILITIES);
|
||||
|
||||
caps.addType(BBOX.class);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
protected Object visitBinarySpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((filter instanceof BBOX))
|
||||
{
|
||||
BBOX bbox = (BBOX)filter;
|
||||
Envelope envelop = ReferencedEnvelope.reference(bbox.getBounds());
|
||||
envelop = intersectionBound(envelop);
|
||||
|
||||
if ((envelop == null) || (envelop.isNull())) {
|
||||
this.out.append(" 1=0 ");
|
||||
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||
return extraData;
|
||||
}
|
||||
|
||||
String pName = findPropertyName(property);
|
||||
|
||||
StringBuffer bboxSQL = new StringBuffer();
|
||||
bboxSQL.append("SDO_FILTER( ");
|
||||
bboxSQL.append(pName);
|
||||
bboxSQL.append(" , ");
|
||||
setLiteralBBox(bboxSQL, pName, envelop, extraData);
|
||||
bboxSQL.append(" , 'mask=anyinteract querytype=WINDOW') = 'TRUE'");
|
||||
|
||||
this.out.append(bboxSQL);
|
||||
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException("Unsupported filter type " + filter.getClass());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Fail to create Filter SQL", e);
|
||||
}
|
||||
|
||||
return extraData;
|
||||
}
|
||||
|
||||
public String findPropertyName(PropertyName expression)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if ((expression instanceof JoinPropertyName))
|
||||
{
|
||||
sb.append(escapeName(((JoinPropertyName)expression).getAlias()));
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
AttributeDescriptor attribute = null;
|
||||
try {
|
||||
attribute = (AttributeDescriptor)expression.evaluate(this.featureType);
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
}
|
||||
String encodedField;
|
||||
if (attribute != null)
|
||||
encodedField = this.fieldEncoder.encode(escapeName(attribute.getLocalName()));
|
||||
else {
|
||||
encodedField = this.fieldEncoder.encode(escapeName(expression.getPropertyName()));
|
||||
}
|
||||
|
||||
sb.append(encodedField);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setLiteralBBox(StringBuffer bboxSQL, String propertyName, Envelope envelope, Object context)
|
||||
{
|
||||
Geometry polygon = JTS.toGeometry(envelope);
|
||||
|
||||
if (!polygon.isValid()) {
|
||||
polygon = polygon.buffer(1.E-005D);
|
||||
}
|
||||
|
||||
this.literalValues.add(polygon);
|
||||
this.dimensions.add(this.currentDimension);
|
||||
|
||||
polygon.setSRID(this.currentSRID.intValue());
|
||||
this.SRIDs.add(this.currentSRID);
|
||||
|
||||
Integer dbSRID = this.dsDialect.getDBSrid(this.featureType.getTypeName(), propertyName);
|
||||
if ((dbSRID != null) && (dbSRID.intValue() <= 0)) {
|
||||
this.dsDialect.getClass(); polygon.setUserData("OracleNullSrid");
|
||||
}
|
||||
|
||||
Class clazz = null;
|
||||
if ((context instanceof Class))
|
||||
clazz = (Class)context;
|
||||
else if (polygon != null) {
|
||||
clazz = polygon.getClass();
|
||||
}
|
||||
this.literalTypes.add(clazz);
|
||||
|
||||
if ((polygon == null) || (this.dialect == null)) {
|
||||
bboxSQL.append("?");
|
||||
}
|
||||
else if (Geometry.class.isAssignableFrom(polygon.getClass())) {
|
||||
int srid = this.currentSRID != null ? this.currentSRID.intValue() : -1;
|
||||
int dimension = this.currentDimension != null ? this.currentDimension.intValue() : -1;
|
||||
this.dialect.prepareGeometryValue(polygon, dimension, srid, Geometry.class, bboxSQL);
|
||||
}
|
||||
else if (this.encodingFunction) {
|
||||
this.dialect.prepareFunctionArgument(clazz, bboxSQL);
|
||||
}
|
||||
else {
|
||||
bboxSQL.append("?");
|
||||
}
|
||||
}
|
||||
|
||||
private Envelope intersectionBound(Envelope envelop)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||
for (Layer layer : layers)
|
||||
{
|
||||
if ((layer instanceof FeatureLayer))
|
||||
{
|
||||
if ((layer.getServerName().equalsIgnoreCase(this.dsDialect.serverName)) &&
|
||||
(layer.getSourceName().equalsIgnoreCase(this.featureType.getTypeName())))
|
||||
{
|
||||
return layer.getBBox().intersection(envelop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
}
|
||||
return envelop;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.AbstractList;
|
||||
|
||||
public class OrdinateList extends AbstractList
|
||||
{
|
||||
final double[] ARRAY;
|
||||
final int OFFSET;
|
||||
final int LEN;
|
||||
final int SIZE;
|
||||
final int START;
|
||||
final int END;
|
||||
final int STEP;
|
||||
|
||||
public OrdinateList(double[] array)
|
||||
{
|
||||
this(array, 0, 1);
|
||||
}
|
||||
|
||||
public OrdinateList(double[] array, int offset, int len) {
|
||||
this(array, offset, len, 0, array.length);
|
||||
}
|
||||
|
||||
public OrdinateList(double[] array, int offset, int len, int start, int end) {
|
||||
this.START = start;
|
||||
this.END = end;
|
||||
this.ARRAY = array;
|
||||
this.OFFSET = offset;
|
||||
this.LEN = len;
|
||||
this.SIZE = (Math.abs(this.START - this.END) / this.LEN);
|
||||
this.STEP = (this.START < this.END ? this.LEN : -this.LEN);
|
||||
|
||||
if (this.ARRAY.length % this.LEN != 0)
|
||||
throw new IllegalArgumentException(
|
||||
"You have requested Coordiantes of " + this.LEN + " ordinates. " +
|
||||
"This is inconsistent with an array of length " + this.ARRAY.length);
|
||||
}
|
||||
|
||||
public Object get(int index)
|
||||
{
|
||||
return new Double(getDouble(index));
|
||||
}
|
||||
|
||||
public double getDouble(int index) {
|
||||
assert (index < this.SIZE) : ("Index: " + index + ", Size: " + this.SIZE);
|
||||
return this.ARRAY[(this.START + this.STEP * index + this.OFFSET)];
|
||||
}
|
||||
public double[] toDoubleArray() {
|
||||
double[] array = new double[size()];
|
||||
for (int i = 0; i < size(); i++) {
|
||||
array[i] = getDouble(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.SIZE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLDecoder;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class PluginUtil
|
||||
{
|
||||
static NumberFormat f;
|
||||
|
||||
public static String getCurrentTime()
|
||||
{
|
||||
long time = System.currentTimeMillis();
|
||||
SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
String strTime = dayTime.format(new Date(time));
|
||||
|
||||
return strTime;
|
||||
}
|
||||
|
||||
public static String toUTF8(String inputStr)
|
||||
{
|
||||
try
|
||||
{
|
||||
return URLDecoder.decode(inputStr, "UTF-8"); } catch (Exception e) {
|
||||
}
|
||||
return inputStr;
|
||||
}
|
||||
|
||||
public static void refineRequestMap(HttpServletRequest req, Map<String, String> reqMap)
|
||||
{
|
||||
Set keyset = req.getParameterMap().keySet();
|
||||
Iterator itr = keyset.iterator();
|
||||
|
||||
while (itr.hasNext())
|
||||
{
|
||||
String key = (String)itr.next();
|
||||
reqMap.put(key.trim().toUpperCase(), toUTF8(req.getParameter(key).trim()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String getClientIP(HttpServletRequest request)
|
||||
{
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static String refineNumber(Object number)
|
||||
{
|
||||
f = NumberFormat.getInstance();
|
||||
f.setMaximumFractionDigits(4);
|
||||
|
||||
return f.format(number);
|
||||
}
|
||||
|
||||
public static String refinePath(String path)
|
||||
{
|
||||
return path.replace(File.separator, "/");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,241 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.factory.CommonFactoryFinder;
|
||||
import org.geotools.factory.GeoTools;
|
||||
import org.geotools.filter.FilterDOMParser;
|
||||
import org.geotools.filter.spatial.ReprojectingFilterVisitor;
|
||||
import org.geotools.filter.v1_1.OGCConfiguration;
|
||||
import org.geotools.filter.visitor.DuplicatingFilterVisitor;
|
||||
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.xml.Configuration;
|
||||
import org.geotools.xml.Parser;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
import org.opengis.filter.Id;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
import org.opengis.filter.identity.Identifier;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class QueryMngr
|
||||
{
|
||||
private static final Configuration filterConfiguration = new OGCConfiguration();
|
||||
public static final FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
||||
|
||||
public static Filter[] getFilters(String str)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
InputSource resource = new InputSource();
|
||||
resource.setCharacterStream(new StringReader(str));
|
||||
return parseFilters(resource);
|
||||
}
|
||||
|
||||
public static Filter[] getFilters(InputStream stream)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
InputSource resource = new InputSource(stream);
|
||||
return parseFilters(resource);
|
||||
}
|
||||
|
||||
private static Filter[] parseFilters(InputSource resource)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
Filter[] filter = null;
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document dom = db.parse(resource);
|
||||
|
||||
NodeList nodes = dom.getElementsByTagNameNS("*", "Filter");
|
||||
|
||||
filter = new Filter[nodes.getLength()];
|
||||
|
||||
for (int j = 0; j < filter.length; j++) {
|
||||
Element filterNode = (Element)nodes.item(j);
|
||||
NodeList list = filterNode.getChildNodes();
|
||||
Node child = null;
|
||||
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
child = list.item(i);
|
||||
|
||||
if ((child != null) && (child.getNodeType() == 1))
|
||||
{
|
||||
filter[j] = FilterDOMParser.parseFilter(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
public static Filter getFilter(String str)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
InputSource resource = new InputSource();
|
||||
resource.setCharacterStream(new StringReader(str));
|
||||
return parseFilter(resource);
|
||||
}
|
||||
|
||||
public static Filter getFilter(InputStream stream)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
InputSource resource = new InputSource(stream);
|
||||
return parseFilter(resource);
|
||||
}
|
||||
|
||||
private static Filter parseFilter(InputSource resource)
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
Parser parser = new Parser(filterConfiguration);
|
||||
return (Filter)parser.parse(resource);
|
||||
}
|
||||
|
||||
private static Filter reProjectionFilter(SimpleFeatureType schema, Filter filter)
|
||||
{
|
||||
ReprojectingFilterVisitor visitor = new ReprojectingFilterVisitor(filterFactory, schema);
|
||||
return (Filter)filter.accept(visitor, null);
|
||||
}
|
||||
|
||||
private static Filter upperCasePropertyNameFilter(Filter filter)
|
||||
{
|
||||
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor()
|
||||
{
|
||||
public Object visit(PropertyName expression, Object extraData)
|
||||
{
|
||||
String pName = expression.getPropertyName().toUpperCase();
|
||||
if (pName.contains(":")) {
|
||||
pName = pName.substring(pName.lastIndexOf(":") + 1);
|
||||
}
|
||||
|
||||
return getFactory(extraData).property(pName, expression.getNamespaceContext());
|
||||
}
|
||||
};
|
||||
return (Filter)filter.accept(fVisitor, null);
|
||||
}
|
||||
|
||||
private static Filter changeFIDFilter(SimpleFeatureType schema, Filter filter)
|
||||
{
|
||||
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor()
|
||||
{
|
||||
public Object visit(Id filter, Object extraData)
|
||||
{
|
||||
Set fIDs = new HashSet();
|
||||
for (Identifier fid : filter.getIdentifiers()) {
|
||||
String str = fid.toString();
|
||||
|
||||
if (str.contains(".")) {
|
||||
String pkStringVlaue = str.substring(str.indexOf(".") + 1);
|
||||
//str = QueryMngr.this.getTypeName() + "." + pkStringVlaue;
|
||||
}
|
||||
|
||||
fIDs.add(getFactory(extraData).featureId(str));
|
||||
}
|
||||
|
||||
return getFactory(extraData).id(fIDs);
|
||||
}
|
||||
};
|
||||
return (Filter)filter.accept(fVisitor, null);
|
||||
}
|
||||
|
||||
private static Filter extractBBoxFilter(SimpleFeatureType schema, Filter filter)
|
||||
{
|
||||
Envelope bounds = (Envelope)filter.accept(ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
|
||||
if ((bounds == null) || (bounds.isNull()))
|
||||
return null;
|
||||
if ((bounds.getMinX() == (-1.0D / 0.0D)) &&
|
||||
(bounds.getMaxX() == (1.0D / 0.0D)) &&
|
||||
(bounds.getMinY() == (-1.0D / 0.0D)) &&
|
||||
(bounds.getMaxY() == (1.0D / 0.0D)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ReferencedEnvelope envelop = ReferencedEnvelope.reference(bounds);
|
||||
String geomField = schema.getGeometryDescriptor().getLocalName();
|
||||
Filter bbox = filterFactory.bbox(filterFactory.property(geomField), envelop);
|
||||
|
||||
return bbox;
|
||||
}
|
||||
|
||||
public static Query reFineQuery(SimpleFeatureType schema, Query query)
|
||||
{
|
||||
query.setFilter(reFineFilter(schema, query.getFilter()));
|
||||
|
||||
Filter bboxFilter = extractBBoxFilter(schema, query.getFilter());
|
||||
if (bboxFilter != null)
|
||||
{
|
||||
CoordinateReferenceSystem reprojCRS = query.getCoordinateSystemReproject();
|
||||
|
||||
Query bboxQuery = new Query(schema.getTypeName(), bboxFilter);
|
||||
bboxQuery.setHints(query.getHints());
|
||||
|
||||
query = DataUtilities.mixQueries(query, bboxQuery, null);
|
||||
|
||||
if ((reprojCRS != null) && (!CRS.equalsIgnoreMetadata(schema.getCoordinateReferenceSystem(), reprojCRS))) {
|
||||
query.setCoordinateSystemReproject(reprojCRS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
query.setTypeName(schema.getTypeName());
|
||||
|
||||
if (query.getProperties() != null)
|
||||
{
|
||||
ArrayList propertys = new ArrayList();
|
||||
|
||||
String geom = schema.getGeometryDescriptor().getLocalName();
|
||||
|
||||
boolean isContain = false;
|
||||
for (String pName : query.getPropertyNames())
|
||||
{
|
||||
pName = pName.trim().toUpperCase();
|
||||
|
||||
if (pName.equals(geom)) {
|
||||
propertys.add(pName);
|
||||
isContain = true;
|
||||
}
|
||||
else if (schema.getDescriptor(pName) != null) {
|
||||
propertys.add(pName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
query.setPropertyNames(propertys);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public static Filter reFineFilter(SimpleFeatureType schema, Filter filter)
|
||||
{
|
||||
Filter uppercaseFilter = upperCasePropertyNameFilter(filter);
|
||||
|
||||
Filter transformFilter = reProjectionFilter(schema, uppercaseFilter);
|
||||
|
||||
Filter changeFidFilter = changeFIDFilter(schema, transformFilter);
|
||||
|
||||
return changeFidFilter;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.collection.DelegateFeatureReader;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||
import org.geotools.data.store.ContentFeatureStore;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.feature.collection.DecoratingSimpleFeatureCollection;
|
||||
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||
import org.geotools.feature.visitor.FeatureAttributeVisitor;
|
||||
import org.geotools.filter.FilterAttributeExtractor;
|
||||
import org.geotools.geometry.jts.JTS;
|
||||
import org.geotools.jdbc.JDBCDataStore;
|
||||
import org.geotools.jdbc.JDBCFeatureStore;
|
||||
import org.geotools.jdbc.PrimaryKey;
|
||||
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.feature.FeatureVisitor;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.MathTransform;
|
||||
|
||||
public class RefindInsertFeatureCollection extends DecoratingSimpleFeatureCollection
|
||||
{
|
||||
ContentFeatureStore featureStore;
|
||||
boolean useProvidedFid;
|
||||
|
||||
public RefindInsertFeatureCollection(SimpleFeature delegate, ContentFeatureStore fStore, boolean providedFid)
|
||||
{
|
||||
this(DataUtilities.collection(delegate), fStore, providedFid);
|
||||
}
|
||||
|
||||
public RefindInsertFeatureCollection(SimpleFeatureCollection delegate, ContentFeatureStore fStore, boolean providedFid) {
|
||||
super(delegate);
|
||||
this.featureStore = fStore;
|
||||
this.useProvidedFid = providedFid;
|
||||
}
|
||||
|
||||
protected boolean canDelegate(FeatureVisitor visitor)
|
||||
{
|
||||
if ((visitor instanceof FeatureAttributeVisitor))
|
||||
{
|
||||
FilterAttributeExtractor extractor = new FilterAttributeExtractor(getSchema());
|
||||
for (Expression e : ((FeatureAttributeVisitor)visitor).getExpressions()) {
|
||||
e.accept(extractor, null);
|
||||
}
|
||||
|
||||
for (PropertyName pname : extractor.getPropertyNameSet()) {
|
||||
AttributeDescriptor att = (AttributeDescriptor)pname.evaluate(getSchema());
|
||||
if (att == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ContentFeatureStore getFeatureStore()
|
||||
{
|
||||
return this.featureStore;
|
||||
}
|
||||
|
||||
public FeatureReader<SimpleFeatureType, SimpleFeature> reader() throws IOException
|
||||
{
|
||||
return new DelegateFeatureReader(getSchema(), features());
|
||||
}
|
||||
|
||||
public SimpleFeatureIterator features()
|
||||
{
|
||||
try {
|
||||
return new O2RefindFeatureIterator(this.delegate.features(), getFeatureStore()); } catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class O2RefindFeatureIterator implements SimpleFeatureIterator
|
||||
{
|
||||
SimpleFeatureIterator delegate;
|
||||
ContentFeatureStore featureStore;
|
||||
SimpleFeatureType featureType;
|
||||
SimpleFeatureBuilder builder;
|
||||
|
||||
public O2RefindFeatureIterator(SimpleFeatureIterator delegate, ContentFeatureStore fStore) throws IOException
|
||||
{
|
||||
this.delegate = delegate;
|
||||
this.featureStore = fStore;
|
||||
this.featureType = this.featureStore.getSchema();
|
||||
this.builder = new SimpleFeatureBuilder(this.featureType);
|
||||
}
|
||||
|
||||
public SimpleFeatureIterator getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this.delegate.hasNext();
|
||||
}
|
||||
|
||||
public SimpleFeature next()
|
||||
{
|
||||
SimpleFeature feature = (SimpleFeature)this.delegate.next();
|
||||
|
||||
String pkColumn = null;
|
||||
if ((this.featureStore instanceof JDBCFeatureStore)) {
|
||||
JDBCFeatureStore jdbcStore = (JDBCFeatureStore)this.featureStore;
|
||||
if ((jdbcStore.getPrimaryKey() != null) &&
|
||||
(jdbcStore.getPrimaryKey().getColumns().size() != 0)) {
|
||||
pkColumn = ((PrimaryKeyColumn)jdbcStore.getPrimaryKey().getColumns().get(0)).getName();
|
||||
}
|
||||
}
|
||||
|
||||
String newID = null;
|
||||
for (AttributeDescriptor att : this.featureType.getAttributeDescriptors())
|
||||
{
|
||||
Object value = feature.getAttribute(att.getLocalName());
|
||||
if (value == null) {
|
||||
value = feature.getAttribute(att.getLocalName().toLowerCase());
|
||||
}
|
||||
|
||||
if ((pkColumn != null) &&
|
||||
(pkColumn.equalsIgnoreCase(att.getLocalName())) &&
|
||||
(value != null)) {
|
||||
newID = value.toString();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ((value != null) && (Geometry.class.isAssignableFrom(value.getClass())))
|
||||
{
|
||||
Geometry tGeom = (Geometry)value;
|
||||
|
||||
if ((tGeom.getUserData() != null) &&
|
||||
((tGeom.getUserData() instanceof CoordinateReferenceSystem)) &&
|
||||
(this.featureType.getCoordinateReferenceSystem() != null))
|
||||
{
|
||||
CoordinateReferenceSystem tCRS = (CoordinateReferenceSystem)tGeom.getUserData();
|
||||
|
||||
if (!CRS.equalsIgnoreMetadata(this.featureType.getCoordinateReferenceSystem(), tCRS))
|
||||
{
|
||||
MathTransform transform = CRS.findMathTransform(tCRS, this.featureType.getCoordinateReferenceSystem(), true);
|
||||
value = JTS.transform(tGeom, transform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((this.featureStore instanceof JDBCFeatureStore)) {
|
||||
JDBCFeatureStore jdbcStore = (JDBCFeatureStore)this.featureStore;
|
||||
|
||||
if ((jdbcStore.getDataStore().getSQLDialect() instanceof OracleDialect))
|
||||
{
|
||||
OracleDialect oDialect = (OracleDialect)jdbcStore.getDataStore().getSQLDialect();
|
||||
Integer srid = oDialect.getDBSrid(this.featureType.getTypeName(), this.featureType.getGeometryDescriptor().getLocalName());
|
||||
|
||||
if ((srid != null) && (srid.intValue() == 0)) {
|
||||
oDialect.getClass(); ((Geometry)value).setUserData("OracleNullSrid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Fail to transform input geometry :: " + e);
|
||||
}
|
||||
|
||||
this.builder.set(att.getLocalName(), value);
|
||||
}
|
||||
|
||||
SimpleFeature newFeature = this.builder.buildFeature(newID);
|
||||
|
||||
if (feature.getUserData().size() > 0) {
|
||||
newFeature.getUserData().putAll(feature.getUserData());
|
||||
}
|
||||
|
||||
if ((RefindInsertFeatureCollection.this.useProvidedFid) && (newID != null))
|
||||
newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.valueOf(true));
|
||||
else {
|
||||
newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.valueOf(false));
|
||||
}
|
||||
|
||||
return newFeature;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
this.delegate.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import javax.swing.ImageIcon;
|
||||
import org.geotools.geometry.jts.TransformedShape;
|
||||
import org.geotools.renderer.style.GraphicStyle2D;
|
||||
import org.geotools.renderer.style.MarkStyle2D;
|
||||
import org.geotools.renderer.style.SLDStyleFactory;
|
||||
import org.geotools.renderer.style.Style2D;
|
||||
import org.geotools.styling.AnchorPoint;
|
||||
import org.geotools.styling.Displacement;
|
||||
import org.geotools.styling.ExternalGraphicImpl;
|
||||
import org.geotools.styling.Fill;
|
||||
import org.geotools.styling.Graphic;
|
||||
import org.geotools.styling.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
import org.geotools.styling.StrokeImpl;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.geotools.util.NumberRange;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class RefineRenderStyleVisitor extends DuplicatingStyleVisitor
|
||||
{
|
||||
SLDStyleFactory sldStyleFactory = new SLDStyleFactory();
|
||||
final NumberRange scaleRange = NumberRange.create(0.0D, 1.7976931348623157E+308D);
|
||||
|
||||
RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
public void visit(PointSymbolizer ps)
|
||||
{
|
||||
PointSymbolizer copy = this.sf.getDefaultPointSymbolizer();
|
||||
|
||||
copy.setGeometry(copy(ps.getGeometry()));
|
||||
copy.setUnitOfMeasure(ps.getUnitOfMeasure());
|
||||
copy.getOptions().putAll(ps.getOptions());
|
||||
|
||||
copy.setGraphic(copy(ps.getGraphic()));
|
||||
|
||||
if ((this.STRICT) &&
|
||||
(!copy.equals(ps))) {
|
||||
throw new IllegalStateException("Was unable to duplicate provided Graphic:" + ps);
|
||||
}
|
||||
|
||||
ExternalGraphicImpl outputGraphic = new ExternalGraphicImpl();
|
||||
outputGraphic.setFormat("png");
|
||||
|
||||
int size = ((Integer)copy.getGraphic().getSize().evaluate(null, Integer.class)).intValue();
|
||||
|
||||
Style2D style2D = this.sldStyleFactory.createStyle(null, copy, this.scaleRange);
|
||||
|
||||
if ((style2D instanceof MarkStyle2D)) {
|
||||
MarkStyle2D markStyle = (MarkStyle2D)style2D;
|
||||
|
||||
TransformedShape tShape = new TransformedShape();
|
||||
tShape.shape = markStyle.getShape();
|
||||
tShape.translate(size / 2, size / 2);
|
||||
|
||||
tShape.scale(size * 0.99D, -size * 0.99D);
|
||||
|
||||
BufferedImage image = new BufferedImage(size, size, 6);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setRenderingHints(this.renderingHints);
|
||||
|
||||
if (markStyle.getFill() != null) {
|
||||
graphics.setPaint(markStyle.getFill());
|
||||
graphics.setComposite(markStyle.getFillComposite());
|
||||
graphics.fill(tShape);
|
||||
}
|
||||
|
||||
if (markStyle.getContour() != null)
|
||||
{
|
||||
if ((markStyle.getStroke() instanceof BasicStroke)) {
|
||||
float width = ((BasicStroke)markStyle.getStroke()).getLineWidth();
|
||||
if (width != 0.0F) {
|
||||
graphics.setPaint(markStyle.getContour());
|
||||
graphics.setStroke(markStyle.getStroke());
|
||||
graphics.setComposite(markStyle.getContourComposite());
|
||||
graphics.draw(tShape);
|
||||
}
|
||||
} else {
|
||||
graphics.setPaint(markStyle.getContour());
|
||||
graphics.setStroke(markStyle.getStroke());
|
||||
graphics.setComposite(markStyle.getContourComposite());
|
||||
graphics.draw(tShape);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
graphics.dispose();
|
||||
|
||||
outputGraphic.setInlineContent(refineImageIcon(image, size, ps.getGraphic().getAnchorPoint(), ps.getGraphic().getDisplacement()));
|
||||
}
|
||||
else if ((style2D instanceof GraphicStyle2D)) {
|
||||
GraphicStyle2D graphicStyle = (GraphicStyle2D)style2D;
|
||||
outputGraphic.setInlineContent(refineImageIcon(graphicStyle.getImage(), size, ps.getGraphic().getAnchorPoint(), ps.getGraphic().getDisplacement()));
|
||||
}
|
||||
|
||||
copy.getGraphic().graphicalSymbols().clear();
|
||||
copy.getGraphic().graphicalSymbols().add(outputGraphic);
|
||||
|
||||
this.pages.push(copy);
|
||||
}
|
||||
|
||||
private ImageIcon refineImageIcon(BufferedImage image, int size, AnchorPoint anchorCopy, Displacement displacementCopy)
|
||||
{
|
||||
double tPointX = 0.0D;
|
||||
double tPointY = 0.0D;
|
||||
|
||||
if (anchorCopy != null) {
|
||||
double aPointX = 0.5D;
|
||||
double aPointY = 0.5D;
|
||||
|
||||
if (anchorCopy.getAnchorPointX() != null) {
|
||||
aPointX = ((Double)anchorCopy.getAnchorPointX().evaluate(null, Double.class)).doubleValue();
|
||||
if (aPointX < 0.0D) aPointX = 0.0D;
|
||||
if (aPointX > 1.0D) aPointX = 1.0D;
|
||||
}
|
||||
if (anchorCopy.getAnchorPointY() != null) {
|
||||
aPointY = ((Double)anchorCopy.getAnchorPointY().evaluate(null, Double.class)).doubleValue();
|
||||
if (aPointY < 0.0D) aPointY = 0.0D;
|
||||
if (aPointY > 1.0D) aPointY = 1.0D;
|
||||
}
|
||||
|
||||
double cPoint = size / 2;
|
||||
tPointX = size * aPointX - cPoint;
|
||||
tPointY = size * aPointY - cPoint;
|
||||
}
|
||||
|
||||
if (displacementCopy != null) {
|
||||
int dPointX = 0;
|
||||
int dPointY = 0;
|
||||
|
||||
if (displacementCopy.getDisplacementX() != null) {
|
||||
dPointX = ((Integer)displacementCopy.getDisplacementX().evaluate(null, Integer.class)).intValue();
|
||||
if (dPointX < -100) dPointX = -100;
|
||||
if (dPointX > 100) dPointX = 100;
|
||||
}
|
||||
if (displacementCopy.getDisplacementY() != null) {
|
||||
dPointY = ((Integer)displacementCopy.getDisplacementY().evaluate(null, Integer.class)).intValue();
|
||||
if (dPointY < -100) dPointY = -100;
|
||||
if (dPointY > 100) dPointY = 100;
|
||||
}
|
||||
|
||||
tPointX += dPointX;
|
||||
tPointY += dPointY;
|
||||
}
|
||||
|
||||
int imgSizeW = (int)Math.round(Math.max(Math.abs(tPointX), Math.abs(tPointY)) * 2.0D + image.getWidth());
|
||||
int imgSizeH = (int)Math.round(Math.max(Math.abs(tPointX), Math.abs(tPointY)) * 2.0D + image.getHeight());
|
||||
|
||||
double imgCenterW = imgSizeW / 2;
|
||||
double imgCenterH = imgSizeH / 2;
|
||||
|
||||
BufferedImage resultImg = new BufferedImage(imgSizeW, imgSizeH, 6);
|
||||
Graphics2D graphics = resultImg.createGraphics();
|
||||
graphics.setRenderingHints(this.renderingHints);
|
||||
graphics.drawImage(image, (int)Math.round(imgCenterW - image.getWidth() / 2 + tPointX), (int)Math.round(imgCenterH - image.getHeight() / 2 + tPointY), null);
|
||||
graphics.dispose();
|
||||
|
||||
return new ImageIcon(resultImg);
|
||||
}
|
||||
|
||||
public void visit(PolygonSymbolizer poly)
|
||||
{
|
||||
PolygonSymbolizer copy = this.sf.createPolygonSymbolizer();
|
||||
copy.setGeometry(copy(poly.getGeometry()));
|
||||
copy.setUnitOfMeasure(poly.getUnitOfMeasure());
|
||||
copy.getOptions().putAll(poly.getOptions());
|
||||
|
||||
copy.setFill(copy(poly.getFill()));
|
||||
copy.setStroke(copy(poly.getStroke()));
|
||||
|
||||
if ((copy.getStroke() == null) && (copy.getFill() != null)) {
|
||||
StrokeImpl stroke = (StrokeImpl)StyleMngr.sf.createStroke(null, null);
|
||||
stroke.setColor(copy.getFill().getColor());
|
||||
copy.setStroke(stroke);
|
||||
}
|
||||
|
||||
if ((this.STRICT) && (!copy.equals(poly))) {
|
||||
throw new IllegalStateException("Was unable to duplicate provided PolygonSymbolizer:" + poly);
|
||||
}
|
||||
|
||||
this.pages.push(copy);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import org.geotools.feature.NameImpl;
|
||||
import org.geotools.filter.visitor.DuplicatingFilterVisitor;
|
||||
import org.geotools.styling.Description;
|
||||
import org.geotools.styling.Extent;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.opengis.feature.type.Name;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
|
||||
public class RefineStyleVisitor extends DuplicatingStyleVisitor
|
||||
{
|
||||
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor(this.ff)
|
||||
{
|
||||
public Object visit(PropertyName expression, Object extraData)
|
||||
{
|
||||
String pName = expression.getPropertyName().toUpperCase();
|
||||
if (pName.contains(":")) {
|
||||
pName = pName.substring(pName.lastIndexOf(":") + 1);
|
||||
}
|
||||
|
||||
return getFactory(extraData).property(pName, expression.getNamespaceContext());
|
||||
}
|
||||
};
|
||||
|
||||
public void visit(StyledLayerDescriptor sld)
|
||||
{
|
||||
if (!ServerUtil.isNullString(sld.getName())) {
|
||||
sld.setName(sld.getName().trim().toUpperCase());
|
||||
}
|
||||
|
||||
super.visit(sld);
|
||||
}
|
||||
|
||||
public void visit(NamedLayer layer)
|
||||
{
|
||||
if (!ServerUtil.isNullString(layer.getName())) {
|
||||
layer.setName(layer.getName().trim().toUpperCase());
|
||||
}
|
||||
|
||||
super.visit(layer);
|
||||
}
|
||||
|
||||
public void visit(UserLayer layer)
|
||||
{
|
||||
if (!ServerUtil.isNullString(layer.getName())) {
|
||||
layer.setName(layer.getName().trim().toUpperCase());
|
||||
}
|
||||
super.visit(layer);
|
||||
}
|
||||
|
||||
public void visit(Style style)
|
||||
{
|
||||
if (!ServerUtil.isNullString(style.getName())) {
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
}
|
||||
|
||||
List<FeatureTypeStyle> ftStyles = style.featureTypeStyles();
|
||||
ArrayList ftsCopy = new ArrayList();
|
||||
if (ftStyles.size() > 0) {
|
||||
for (FeatureTypeStyle fts : ftStyles) {
|
||||
if (fts != null) {
|
||||
fts.accept(this);
|
||||
ftsCopy.add((FeatureTypeStyle)this.pages.pop());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Style copy = null;
|
||||
if ((style instanceof NamedStyle)) {
|
||||
copy = this.sf.createNamedStyle();
|
||||
} else {
|
||||
copy = this.sf.createStyle();
|
||||
copy.setDefault(style.isDefault());
|
||||
}
|
||||
|
||||
copy.featureTypeStyles().addAll(ftsCopy);
|
||||
|
||||
copy.setName(style.getName());
|
||||
copy.getDescription().setAbstract(style.getDescription().getAbstract());
|
||||
copy.getDescription().setTitle(style.getDescription().getTitle());
|
||||
|
||||
if ((this.STRICT) && (!copy.equals(style))) {
|
||||
throw new IllegalStateException("Was unable to duplicate provided Style:" + style);
|
||||
}
|
||||
this.pages.push(copy);
|
||||
}
|
||||
|
||||
public void visit(FeatureTypeStyle fts)
|
||||
{
|
||||
if (!ServerUtil.isNullString(fts.getName())) {
|
||||
fts.setName(fts.getName().trim().toUpperCase());
|
||||
}
|
||||
|
||||
Set typeNames = new HashSet();
|
||||
|
||||
Iterator names = fts.featureTypeNames().iterator();
|
||||
while (names.hasNext()) {
|
||||
Name name = (Name)names.next();
|
||||
if (!ServerUtil.isNullString(name.getLocalPart()))
|
||||
{
|
||||
String typeNameList = name.getLocalPart().trim().toUpperCase();
|
||||
|
||||
String[] tempNames = typeNameList.split("\\,");
|
||||
for (String typeName : tempNames)
|
||||
{
|
||||
typeName = typeName.trim();
|
||||
|
||||
String[] codes = typeName.split(":");
|
||||
|
||||
if (codes.length == 1)
|
||||
typeNames.add(new NameImpl(codes[0].trim()));
|
||||
else if (codes.length == 2) {
|
||||
typeNames.add(new NameImpl(codes[1].trim()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fts.featureTypeNames().clear();
|
||||
fts.featureTypeNames().addAll(typeNames);
|
||||
|
||||
super.visit(fts);
|
||||
}
|
||||
|
||||
public void visit(Rule rule)
|
||||
{
|
||||
if (!ServerUtil.isNullString(rule.getName())) {
|
||||
rule.setName(rule.getName().trim().toUpperCase());
|
||||
}
|
||||
super.visit(rule);
|
||||
}
|
||||
|
||||
protected Extent copy(Extent extent)
|
||||
{
|
||||
String name = extent.getName();
|
||||
String value = extent.getValue();
|
||||
Extent copy = this.sf.createExtent(name.toUpperCase(), value);
|
||||
return copy;
|
||||
}
|
||||
|
||||
protected Filter copy(Filter filter)
|
||||
{
|
||||
if (filter == null) return null;
|
||||
return (Filter)filter.accept(this.fVisitor, this.ff);
|
||||
}
|
||||
|
||||
protected Expression copy(Expression expression)
|
||||
{
|
||||
if (expression == null) return null;
|
||||
return (Expression)expression.accept(this.fVisitor, this.ff);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,350 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||
import org.geotools.feature.FeatureIterator;
|
||||
import org.geotools.feature.FeatureTypes;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.opengis.feature.FeatureVisitor;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.opengis.feature.type.AttributeDescriptor;
|
||||
import org.opengis.feature.type.GeometryDescriptor;
|
||||
import org.opengis.feature.type.PropertyDescriptor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.sort.SortBy;
|
||||
import org.opengis.geometry.BoundingBox;
|
||||
import org.opengis.util.ProgressListener;
|
||||
|
||||
public class RenderFeatureCollection
|
||||
implements SimpleFeatureCollection {
|
||||
protected RenderFeatureSource featureSource;
|
||||
protected Query query;
|
||||
|
||||
protected RenderFeatureCollection(RenderFeatureSource featureSource, Query query) {
|
||||
this.featureSource = featureSource;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public SimpleFeatureType getSchema() {
|
||||
return this.featureSource.getSchema();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return "Rendering FeatureCollection";
|
||||
}
|
||||
|
||||
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
|
||||
this.featureSource.accepts(this.query, visitor, progress);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public ReferencedEnvelope getBounds() {
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> reader = null;
|
||||
try {
|
||||
ReferencedEnvelope result = this.featureSource.getBounds(this.query);
|
||||
if (result != null) {
|
||||
ReferencedEnvelope referencedEnvelope = result;
|
||||
return referencedEnvelope;
|
||||
}
|
||||
Query q = new Query(this.query);
|
||||
ArrayList<String> geometries = new ArrayList<String>();
|
||||
Iterator iterator = this.getSchema().getAttributeDescriptors().iterator();
|
||||
while (true) {
|
||||
if (!iterator.hasNext()) {
|
||||
if (geometries.size() != 0) break;
|
||||
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope();
|
||||
return referencedEnvelope;
|
||||
}
|
||||
AttributeDescriptor ad = (AttributeDescriptor)iterator.next();
|
||||
if (!(ad instanceof GeometryDescriptor)) continue;
|
||||
geometries.add(ad.getLocalName());
|
||||
}
|
||||
q.setPropertyNames(geometries);
|
||||
reader = this.featureSource.getReader(q);
|
||||
while (true) {
|
||||
if (!reader.hasNext()) {
|
||||
if (result == null) break;
|
||||
ReferencedEnvelope referencedEnvelope = result;
|
||||
return referencedEnvelope;
|
||||
}
|
||||
SimpleFeature f = (SimpleFeature)reader.next();
|
||||
ReferencedEnvelope featureBounds = ReferencedEnvelope.reference((BoundingBox)f.getBounds());
|
||||
if (result == null) {
|
||||
result = featureBounds;
|
||||
continue;
|
||||
}
|
||||
if (featureBounds == null) continue;
|
||||
result.expandToInclude((Envelope)featureBounds);
|
||||
}
|
||||
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(this.getSchema().getCoordinateReferenceSystem());
|
||||
return referencedEnvelope;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public boolean contains(Object o) {
|
||||
SimpleFeatureIterator e = null;
|
||||
try {
|
||||
e = this.features();
|
||||
if (o == null) {
|
||||
if (e.hasNext()) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.hasNext()) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
if (e != null) {
|
||||
e.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Iterator<?> e = c.iterator();
|
||||
try {
|
||||
if (e.hasNext()) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally {
|
||||
if (e instanceof FeatureIterator) {
|
||||
((FeatureIterator)e).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
boolean bl = false;
|
||||
Query notEmptyQuery = new Query(this.query);
|
||||
notEmptyQuery.setMaxFeatures(1);
|
||||
AttributeDescriptor smallAttribute = this.getSmallAttributeInSchema();
|
||||
if (smallAttribute != null) {
|
||||
notEmptyQuery.setPropertyNames(Collections.singletonList(smallAttribute.getLocalName()));
|
||||
}
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> fr;
|
||||
try {
|
||||
fr = this.featureSource.getReader(notEmptyQuery);
|
||||
try {
|
||||
bl = !fr.hasNext();
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
try {
|
||||
fr.close();
|
||||
throw throwable;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
return bl;
|
||||
|
||||
}
|
||||
|
||||
private AttributeDescriptor getSmallAttributeInSchema() {
|
||||
AttributeDescriptor chosen = null;
|
||||
for (AttributeDescriptor ad : this.getSchema().getAttributeDescriptors()) {
|
||||
if (chosen != null && this.size(ad) >= this.size(chosen)) continue;
|
||||
chosen = ad;
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> fr = null;
|
||||
try {
|
||||
int size = this.featureSource.getCount(this.query);
|
||||
if (size >= 0) {
|
||||
int n = size;
|
||||
return n;
|
||||
}
|
||||
AttributeDescriptor chosen = this.getSmallAttributeInSchema();
|
||||
Query q = new Query(this.query);
|
||||
if (chosen != null) {
|
||||
q.setPropertyNames(Collections.singletonList(chosen.getLocalName()));
|
||||
}
|
||||
fr = this.featureSource.getReader(q);
|
||||
int count = 0;
|
||||
while (fr.hasNext()) {
|
||||
fr.next();
|
||||
++count;
|
||||
}
|
||||
int n = count;
|
||||
return n;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if (fr != null) {
|
||||
try {
|
||||
fr.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int size(AttributeDescriptor ad) {
|
||||
Class binding = ad.getType().getBinding();
|
||||
if (binding.isPrimitive() || Number.class.isAssignableFrom(binding) || Date.class.isAssignableFrom(binding)) {
|
||||
return 4;
|
||||
}
|
||||
if (binding.equals(String.class)) {
|
||||
int fieldLen = FeatureTypes.getFieldLength((PropertyDescriptor)ad);
|
||||
if (fieldLen > 0) {
|
||||
return fieldLen * 2;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
if (Point.class.isAssignableFrom(binding)) {
|
||||
return 12;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
ArrayList<SimpleFeature> array = new ArrayList<SimpleFeature>();
|
||||
SimpleFeatureIterator e = null;
|
||||
try {
|
||||
e = this.features();
|
||||
while (e.hasNext()) {
|
||||
array.add((SimpleFeature)e.next());
|
||||
}
|
||||
Object[] objectArray = array.toArray(new SimpleFeature[array.size()]);
|
||||
return objectArray;
|
||||
}
|
||||
finally {
|
||||
if (e != null) {
|
||||
e.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
int size = this.size();
|
||||
if (array.length < size) {
|
||||
array = (T[])Array.newInstance(array.getClass().getComponentType(), size);
|
||||
}
|
||||
SimpleFeatureIterator it = this.features();
|
||||
try {
|
||||
T[] result = array;
|
||||
int i = 0;
|
||||
while (it.hasNext() && i < size) {
|
||||
result[i] = (T) it.next();
|
||||
++i;
|
||||
}
|
||||
if (array.length > size) {
|
||||
array[size] = null;
|
||||
}
|
||||
Object[] objectArray = array;
|
||||
return (T[]) objectArray;
|
||||
}
|
||||
finally {
|
||||
if (it != null) {
|
||||
it.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleFeatureIterator features() {
|
||||
try {
|
||||
return new RenderFeatureIterator(this.featureSource.getReader(this.query));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleFeatureCollection subCollection(Filter filter) {
|
||||
Query query = new Query();
|
||||
query.setFilter(filter);
|
||||
query = DataUtilities.mixQueries((Query)this.query, (Query)query, null);
|
||||
return new RenderFeatureCollection(this.featureSource, query);
|
||||
}
|
||||
|
||||
public SimpleFeatureCollection sort(SortBy sort) {
|
||||
Query query = new Query();
|
||||
query.setSortBy(new SortBy[]{sort});
|
||||
query = DataUtilities.mixQueries((Query)this.query, (Query)query, null);
|
||||
return new RenderFeatureCollection(this.featureSource, query);
|
||||
}
|
||||
|
||||
class RenderFeatureIterator
|
||||
implements SimpleFeatureIterator {
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> delegate;
|
||||
|
||||
public RenderFeatureIterator(FeatureReader<SimpleFeatureType, SimpleFeature> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
try {
|
||||
return this.delegate.hasNext();
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleFeature next() {
|
||||
try {
|
||||
return (SimpleFeature)this.delegate.next();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.delegate.close();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
package geoinfo.map.myMap;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.feature.FeatureIterator;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.renderer.ScreenMap;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
|
||||
class RenderFeatureReader
|
||||
implements FeatureReader<SimpleFeatureType, SimpleFeature>
|
||||
{
|
||||
SimpleFeatureSource source;
|
||||
FeatureIterator<SimpleFeature> featureIterator;
|
||||
Query query;
|
||||
double simplificationDistance = 0.0D;
|
||||
ReferencedEnvelope targetBBox = null;
|
||||
ScreenMap screenMap = null;
|
||||
SimpleFeature nextFeature;
|
||||
GeometryFactory geometryFactory = new GeometryFactory();
|
||||
|
||||
public RenderFeatureReader(SimpleFeatureSource source, Query query) throws IOException
|
||||
{
|
||||
this.source = source;
|
||||
this.featureIterator = source.getFeatures(query).features();
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
if (this.featureIterator != null)
|
||||
try {
|
||||
this.featureIterator.close();
|
||||
} catch (Exception localException) {
|
||||
}
|
||||
finally {
|
||||
this.featureIterator = null;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleFeatureType getFeatureType()
|
||||
{
|
||||
return (SimpleFeatureType)this.source.getSchema();
|
||||
}
|
||||
|
||||
public SimpleFeature next()
|
||||
throws IOException, IllegalArgumentException, NoSuchElementException
|
||||
{
|
||||
if (this.featureIterator == null) {
|
||||
throw new NoSuchElementException("Iterator has been closed");
|
||||
}
|
||||
|
||||
if (hasNext()) {
|
||||
SimpleFeature result = this.nextFeature;
|
||||
this.nextFeature = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
close();
|
||||
throw new NoSuchElementException("hasNext() returned false");
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
{
|
||||
try
|
||||
{
|
||||
while ((this.nextFeature == null) && (this.featureIterator.hasNext()))
|
||||
{
|
||||
SimpleFeature feature = (SimpleFeature)this.featureIterator.next();
|
||||
Geometry geometry = (Geometry)feature.getDefaultGeometry();
|
||||
Envelope envelope = geometry.getEnvelopeInternal();
|
||||
|
||||
if ((this.targetBBox == null) ||
|
||||
(this.targetBBox.isNull()) ||
|
||||
(this.targetBBox.intersects(envelope)))
|
||||
{
|
||||
if ((this.simplificationDistance > 0.0D) &&
|
||||
(envelope.getWidth() < this.simplificationDistance) &&
|
||||
(envelope.getHeight() < this.simplificationDistance))
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((this.screenMap == null) || (!this.screenMap.checkAndSet(envelope)));
|
||||
}
|
||||
catch (Exception localException1)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
this.nextFeature = feature;
|
||||
}
|
||||
}
|
||||
return this.nextFeature != null;
|
||||
} catch (Exception e) {
|
||||
close();
|
||||
}return false;
|
||||
}
|
||||
|
||||
public void setSimplificationDistance(double simplificationDistance)
|
||||
{
|
||||
this.simplificationDistance = simplificationDistance;
|
||||
}
|
||||
|
||||
public void setTargetBBox(ReferencedEnvelope targetBBox)
|
||||
{
|
||||
this.targetBBox = targetBBox;
|
||||
}
|
||||
|
||||
public void setScreenMap(ScreenMap screenMap)
|
||||
{
|
||||
this.screenMap = screenMap;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue