feat: 발주기관 지도에 전체 시추공 나오도록 표시
parent
1ee135bf9c
commit
396b300848
5
list.txt
5
list.txt
|
|
@ -11,7 +11,6 @@ src\main\webapp\WEB-INF\views\drilling\common\includeTopMenu.jsp
|
||||||
src\main\webapp\WEB-INF\views\drilling\home\drilling_index.jsp
|
src\main\webapp\WEB-INF\views\drilling\home\drilling_index.jsp
|
||||||
src\main\webapp\com\css\common.v2.0.css
|
src\main\webapp\com\css\common.v2.0.css
|
||||||
src\main\webapp\com\css\common.v2.0.css.map
|
src\main\webapp\com\css\common.v2.0.css.map
|
||||||
src\main\webapp\com\img\drilling\maps\dokdo_active_alone.svg
|
|
||||||
src\main\webapp\com\img\drilling\maps\uleungdo_active_alone.svg
|
|
||||||
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry_project.jsp
|
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry_project.jsp
|
||||||
src\main\webapp\WEB-INF\views\drilling\home\drilling_index.jsp
|
src\main\webapp\WEB-INF\views\drilling\home\drilling_index.jsp
|
||||||
|
src\main\java\geoinfo\drilling\home\DrillingHomeController.java
|
||||||
|
|
@ -143,11 +143,13 @@ public class DrillingHomeController {
|
||||||
EgovMap mbr = drillingInquiryService.getTblMasterCompanyMbrByComCode(request, params, String.valueOf(request.getSession().getAttribute("USERID")));
|
EgovMap mbr = drillingInquiryService.getTblMasterCompanyMbrByComCode(request, params, String.valueOf(request.getSession().getAttribute("USERID")));
|
||||||
model.addAttribute("mbr", mbr);
|
model.addAttribute("mbr", mbr);
|
||||||
|
|
||||||
double nOffsetKm = 2.0f; // 2Km 밖 까지 허용한다.
|
if( mbr != null ) {
|
||||||
params.put("MIN_X", MyUtil.getDoubleFromObject( mbr.get("minX") ) - nOffsetKm*1000);
|
double nOffsetKm = 2.0f; // 2Km 밖 까지 허용한다.
|
||||||
params.put("MIN_Y", MyUtil.getDoubleFromObject( mbr.get("minY") ) - nOffsetKm*1000);
|
params.put("MIN_X", MyUtil.getDoubleFromObject( mbr.get("minX") ) - nOffsetKm*1000);
|
||||||
params.put("MAX_X", MyUtil.getDoubleFromObject( mbr.get("maxX") ) + nOffsetKm*1000);
|
params.put("MIN_Y", MyUtil.getDoubleFromObject( mbr.get("minY") ) - nOffsetKm*1000);
|
||||||
params.put("MAX_Y", MyUtil.getDoubleFromObject( mbr.get("maxY") ) + nOffsetKm*1000);
|
params.put("MAX_X", MyUtil.getDoubleFromObject( mbr.get("maxX") ) + nOffsetKm*1000);
|
||||||
|
params.put("MAX_Y", MyUtil.getDoubleFromObject( mbr.get("maxY") ) + nOffsetKm*1000);
|
||||||
|
}
|
||||||
|
|
||||||
model.put("data", drillingHomeService.drillingMapSearchHoleWithMbr(params));
|
model.put("data", drillingHomeService.drillingMapSearchHoleWithMbr(params));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,304 @@
|
||||||
|
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 entries = list.getEntries();
|
||||||
|
for (Map.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class AWTLabelUtil {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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;
|
||||||
|
import org.opengis.util.NameSpace;
|
||||||
|
|
||||||
|
public class CRSMngr {
|
||||||
|
private static final O2CRSFactory crsFactory = new O2CRSFactory();
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class ConnJDBC {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class ConnMngr {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,255 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,491 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
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.StyleFactory;
|
||||||
|
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 java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
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.StyleFactory;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String sVal = params.getStringValue("conf.service.ref.source");
|
||||||
|
sVal = sVal.trim().toUpperCase();
|
||||||
|
this.sourceName = sVal;
|
||||||
|
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(getLayerType(), getServerName(), getSourceName());
|
||||||
|
|
||||||
|
this.bbox = featureSource.getBounds();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getValue("conf.service.sld") == null) {
|
||||||
|
Style style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||||
|
setCurrentStyle(style);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||||
|
} else {
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)params.getValue("conf.service.sld");
|
||||||
|
initServiceStyle(sld, false);
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Set Style From DB :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||||
|
|
||||||
|
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
||||||
|
if (sld != null) {
|
||||||
|
initServiceStyle(sld, false);
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Override 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() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isUseCache().booleanValue()) {
|
||||||
|
O2DSMngr.putMemoryFeatureSource(getLayerType(), getServerName(), getSourceName(), Filter.INCLUDE);
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Now use memery DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]",
|
||||||
|
"Fail to make memery DataStore. Now use common DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write)
|
||||||
|
{
|
||||||
|
Style defaultStyle = null;
|
||||||
|
ConcurrentHashMap tempStore = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
Iterator iterLayer = sld.layers().iterator();
|
||||||
|
Iterator iterStyle;
|
||||||
|
label233: for (; iterLayer.hasNext();
|
||||||
|
iterStyle.hasNext())
|
||||||
|
{
|
||||||
|
StyledLayer styledLayer = (StyledLayer)iterLayer.next();
|
||||||
|
|
||||||
|
if ((!ServerUtil.isNullString(styledLayer.getName())) &&
|
||||||
|
(!styledLayer.getName().equalsIgnoreCase(getName())))
|
||||||
|
{
|
||||||
|
break label233;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.writeServiceSLD110(getStyleSLD());
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initServiceStyle(StyledLayer styledLayer, boolean write)
|
||||||
|
{
|
||||||
|
Style defaultStyle = null;
|
||||||
|
ConcurrentHashMap tempStore = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
if ((!ServerUtil.isNullString(styledLayer.getName())) &&
|
||||||
|
(!styledLayer.getName().equalsIgnoreCase(getName()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator iterStyle = getStyleIterator(styledLayer);
|
||||||
|
while (iterStyle.hasNext()) {
|
||||||
|
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.writeServiceSLD110(getStyleSLD());
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initServiceStyle(Style style, boolean write)
|
||||||
|
{
|
||||||
|
if ((style == null) || ((style instanceof NamedStyle))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(style.getName()))
|
||||||
|
style.setName(getName());
|
||||||
|
else {
|
||||||
|
style.setName(style.getName().trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.styleStore.put(style.getName(), style);
|
||||||
|
|
||||||
|
if ((style.isDefault()) || (style.getName().equalsIgnoreCase(getCurrentStyle().getName()))) {
|
||||||
|
setCurrentStyle(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write)
|
||||||
|
StyleMngr.writeServiceSLD110(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(getLayerType(), getServerName(), getSourceName());
|
||||||
|
if (!CRS.equalsIgnoreMetadata(getCRS(), ((SimpleFeatureType)featureSource.getSchema()).getCoordinateReferenceSystem())) {
|
||||||
|
featureSource = O2DSMngr.changeCRSFeatureSource(getLayerType(), getServerName(), getSourceName(), getCRS());
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for FeatureSouce [" + getSourceName() + "]");
|
||||||
|
|
||||||
|
updateBBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]",
|
||||||
|
"Fail to update CRS for FeatureSouce [" + getSourceName() + "] :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateBBox()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(getLayerType(), getServerName(), getSourceName());
|
||||||
|
this.bbox = featureSource.getBounds();
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Style getRenderStyle(String styleName)
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(styleName)) {
|
||||||
|
styleName = "DEFAULT";
|
||||||
|
}
|
||||||
|
styleName = styleName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (this.renderStyles.containsKey(styleName)) {
|
||||||
|
return (Style)this.renderStyles.get(styleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Style style = getStyle(styleName);
|
||||||
|
if (style == null) {
|
||||||
|
style = getCurrentStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
||||||
|
style.accept(sVisitor);
|
||||||
|
style = (Style)sVisitor.getCopy();
|
||||||
|
|
||||||
|
this.renderStyles.put(styleName, style);
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Style getStyle(String styleName)
|
||||||
|
{
|
||||||
|
if (!ServerUtil.isNullString(styleName)) {
|
||||||
|
return (Style)this.styleStore.get(styleName.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContainStyle(String styleName)
|
||||||
|
{
|
||||||
|
if ((!ServerUtil.isNullString(styleName)) &&
|
||||||
|
(this.styleStore.containsKey(styleName.trim().toUpperCase()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StyledLayerDescriptor getStyleSLD(String[] styleNames)
|
||||||
|
{
|
||||||
|
if ((styleNames == null) || (styleNames.length == 0)) {
|
||||||
|
return getStyleSLD();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList styles = new ArrayList();
|
||||||
|
for (String styleName : styleNames)
|
||||||
|
{
|
||||||
|
if (!ServerUtil.isNullString(styleName))
|
||||||
|
{
|
||||||
|
styleName = styleName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (this.styleStore.containsKey(styleName)) {
|
||||||
|
styles.add((Style)this.styleStore.get(styleName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||||
|
layer.setName(getName());
|
||||||
|
layer.styles().addAll(styles);
|
||||||
|
|
||||||
|
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||||
|
sld.addStyledLayer(layer);
|
||||||
|
sld.setName(getName());
|
||||||
|
|
||||||
|
return sld;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(styleName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
styleName = styleName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (this.styleStore.remove(styleName) == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCurrentStyle().getName().equalsIgnoreCase(styleName))
|
||||||
|
{
|
||||||
|
Style style = getStyle(getName());
|
||||||
|
if (style == null)
|
||||||
|
{
|
||||||
|
if (this.styleStore.isEmpty())
|
||||||
|
style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||||
|
else {
|
||||||
|
style = (Style)this.styleStore.values().iterator().next();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentStyle(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write)
|
||||||
|
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAllStyle(boolean write)
|
||||||
|
{
|
||||||
|
if (this.styleStore.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.styleStore.clear();
|
||||||
|
this.renderStyles.clear();
|
||||||
|
|
||||||
|
setCurrentStyle(StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName()));
|
||||||
|
|
||||||
|
if (write)
|
||||||
|
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class GWVectorDriver {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,476 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 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) {
|
||||||
|
String 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) {
|
||||||
|
String 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 e) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class GeoWaveDataStore {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,335 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class GeometryMngr {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
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(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,533 @@
|
||||||
|
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.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.data.DataAccessFactory.Param;
|
||||||
|
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 = Boolean.valueOf(true);
|
||||||
|
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 = Boolean.TRUE;
|
||||||
|
|
||||||
|
public static synchronized void initLayers()
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Connections");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
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]", "-----------------------------------");
|
||||||
|
initJdbcLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initDataStore()
|
||||||
|
{
|
||||||
|
dataStores = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
Statement st = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
|
||||||
|
synchronized (dataStores)
|
||||||
|
{
|
||||||
|
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(sIP, "wldhxn");
|
||||||
|
sPort = EncryptUtil.decrypt(sPort, "wldhxn");
|
||||||
|
database = EncryptUtil.decrypt(database, "wldhxn");
|
||||||
|
|
||||||
|
dbUser = EncryptUtil.decrypt(dbUser, "wldhxn");
|
||||||
|
dbPass = EncryptUtil.decrypt(dbPass, "wldhxn");
|
||||||
|
}
|
||||||
|
|
||||||
|
String pkCol = "GID";
|
||||||
|
String tStr = rs.getString("PK_COLUMN");
|
||||||
|
if (tStr != null) {
|
||||||
|
pkCol = tStr.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean useSpatial = DEFAULT_USE_SPATIAL.booleanValue();
|
||||||
|
tStr = rs.getString("USE_SPATIAL").trim();
|
||||||
|
if ((!ServerUtil.isNullString(tStr)) && (tStr.equalsIgnoreCase("N"))) {
|
||||||
|
useSpatial = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int minConn = 10;
|
||||||
|
try {
|
||||||
|
minConn = Integer.parseInt(rs.getString("MIN_CONN"));
|
||||||
|
} catch (Exception localException1) {
|
||||||
|
}
|
||||||
|
int maxConn = 25;
|
||||||
|
try {
|
||||||
|
maxConn = Integer.parseInt(rs.getString("MAX_CONN"));
|
||||||
|
} catch (Exception localException2) {
|
||||||
|
}
|
||||||
|
int fetchSize = 50;
|
||||||
|
try {
|
||||||
|
fetchSize = Integer.parseInt(rs.getString("FETCH_SIZE"));
|
||||||
|
}
|
||||||
|
catch (Exception localException3)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap params = new HashMap();
|
||||||
|
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, Integer.valueOf(minConn));
|
||||||
|
params.put(O2DSFactory.MAXCONN.key, Integer.valueOf(maxConn));
|
||||||
|
params.put(O2DSFactory.MAXWAIT.key, Integer.valueOf(30));
|
||||||
|
params.put(O2DSFactory.VALIDATECONN.key, Boolean.FALSE);
|
||||||
|
|
||||||
|
params.put(O2DSFactory.FETCHSIZE.key, Integer.valueOf(fetchSize));
|
||||||
|
params.put(O2DSFactory.MAX_OPEN_PREPARED_STATEMENTS.key, Integer.valueOf(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, Boolean.valueOf(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");
|
||||||
|
} finally {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initJdbcLayer()
|
||||||
|
{
|
||||||
|
Connection connection = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
InputStream is = null;
|
||||||
|
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 grpList = new ArrayList();
|
||||||
|
if (rs != null) {
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "");
|
||||||
|
|
||||||
|
String mapName = rs.getString("MAP_NAME");
|
||||||
|
if (ServerUtil.isNullString(mapName)) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME is NULL");
|
||||||
|
}
|
||||||
|
else if (!mapName.trim().equalsIgnoreCase(ServerContext.getMap().getName())) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]",
|
||||||
|
"Skip create layer :: MAP_NAME [" + mapName + "] is not equal ServiceMapName [" + ServerContext.getMap().getName() + "]");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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(is);
|
||||||
|
ByteArrayInputStream cloneIs = new ByteArrayInputStream(bytes);
|
||||||
|
sld = StyleMngr.parseSLD(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", mapName);
|
||||||
|
params.setValue("conf.service.layer.name", layerName);
|
||||||
|
params.setValue("conf.service.ref.server", refServer);
|
||||||
|
params.setValue("conf.service.ref.source", refSource);
|
||||||
|
params.setValue("conf.service.ref.srid", refSrid);
|
||||||
|
params.setValue("conf.service.sld", sld);
|
||||||
|
|
||||||
|
if (ServerUtil.getBooleanValue(useCache))
|
||||||
|
params.setValue("conf.service.use.cache", Boolean.valueOf(true));
|
||||||
|
else {
|
||||||
|
params.setValue("conf.service.use.cache", Boolean.valueOf(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
params.setValue("conf.service.last.update", lastUpdate);
|
||||||
|
params.setValue("conf.service.description", 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(refServer))
|
||||||
|
throw new Exception("REF_SERVER value is NULL.");
|
||||||
|
if (getDataStore(refServer) == null) {
|
||||||
|
throw new Exception("REF_SERVER [" + refServer + "] is not exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
layer = LayerFactory.createLayer(LayerFactory.LayerType.JDBC, 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.WMS, 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.WCS, 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < grpList.size(); i++) {
|
||||||
|
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.GROUP, (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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
} finally {
|
||||||
|
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 = getDataStore(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
throw new IOException("JdbcLayer DataStore is not exist [" + storeName + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(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(layerSource)) {
|
||||||
|
throw new IOException("JdbcLayer LayerSource is null");
|
||||||
|
}
|
||||||
|
layerSource = layerSource.trim().toUpperCase();
|
||||||
|
|
||||||
|
List layers = Arrays.asList(store.getTypeNames());
|
||||||
|
if (!layers.contains(layerSource)) {
|
||||||
|
throw new IOException("JdbcLayer LayerSource [" + layerSource + "] is not exist in this JdbcDataStore [" + storeName + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS(crsCode, true);
|
||||||
|
if (crs == null) {
|
||||||
|
crs = CRS.decode("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.JDBC, params);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
|
||||||
|
return (FeatureLayer)layer;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dirtyDataStores = dataStores;
|
||||||
|
initLayers();
|
||||||
|
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(storeName))
|
||||||
|
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||||
|
if (dataStores.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (JDBCDataStore)dataStores.get(storeName.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void disposeDirtyDataStores()
|
||||||
|
{
|
||||||
|
if (dirtyDataStores == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator iter = dirtyDataStores.values().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
JDBCDataStore store = (JDBCDataStore)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()) {
|
||||||
|
JDBCDataStore store = (JDBCDataStore)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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized boolean disposeDataStore(String storeName)
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(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();
|
||||||
|
|
||||||
|
synchronized (dataStores)
|
||||||
|
{
|
||||||
|
JDBCDataStore store = (JDBCDataStore)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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class KLISLabelUtil {
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,67 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,588 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,192 @@
|
||||||
|
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(sVal)) {
|
||||||
|
throw new IllegalArgumentException("MapName is NULL.");
|
||||||
|
}
|
||||||
|
this.mapName = sVal.trim().toUpperCase();
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.layer.name");
|
||||||
|
if (ServerUtil.isNullString(sVal)) {
|
||||||
|
throw new IllegalArgumentException("Layer Name is NULL.");
|
||||||
|
}
|
||||||
|
this.layerName = sVal.trim().toUpperCase();
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.ref.server");
|
||||||
|
if (ServerUtil.isNullString(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(srid.intValue(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.layerCRS = crs;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("SRID value is not available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean bVal = params.getBooleanValue("conf.service.use.cache");
|
||||||
|
if (bVal == null)
|
||||||
|
this.layerUseCache = Boolean.valueOf(false);
|
||||||
|
else {
|
||||||
|
this.layerUseCache = bVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date dateVal = params.getDateValue("conf.service.last.update");
|
||||||
|
if (dateVal == null)
|
||||||
|
this.layerLastUpdate = new Date();
|
||||||
|
else {
|
||||||
|
this.layerLastUpdate = dateVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.layerTitle = ("O2Map Web Layer : " + this.layerName);
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.description");
|
||||||
|
if (ServerUtil.isNullString(sVal))
|
||||||
|
this.layerAbstract = "This Layer served FEATURE or IMAGE or COVERAGE on O2Map Web.";
|
||||||
|
else {
|
||||||
|
this.layerAbstract = sVal.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.source.path");
|
||||||
|
if (ServerUtil.isNullString(sVal))
|
||||||
|
this.sourcPath = "";
|
||||||
|
else {
|
||||||
|
this.sourcPath = sVal.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.hashtag");
|
||||||
|
if (ServerUtil.isNullString(sVal))
|
||||||
|
this.hashTag = "";
|
||||||
|
else {
|
||||||
|
this.hashTag = sVal.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.author.id");
|
||||||
|
if (ServerUtil.isNullString(sVal))
|
||||||
|
this.autorID = "Anonymous";
|
||||||
|
else {
|
||||||
|
this.autorID = sVal.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.source.type");
|
||||||
|
if (ServerUtil.isNullString(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(CRS.toSRS(this.layerCRS));
|
||||||
|
|
||||||
|
if (CRS.equalsIgnoreMetadata(this.layerCRS, 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();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class LayerFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
public static 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;
|
||||||
|
|
||||||
|
private 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
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 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 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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,219 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,223 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.geotools.styling.DescriptionImpl;
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
setName("");
|
||||||
|
if (getDescription() != null) {
|
||||||
|
getDescription().setTitle("");
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWrapTileText()
|
||||||
|
{
|
||||||
|
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
||||||
|
return 0.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.wrapTileText.doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWrapTileText(double dValue)
|
||||||
|
{
|
||||||
|
if (dValue > 1.0D) {
|
||||||
|
dValue = 1.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
||||||
|
this.wrapTileText = Double.valueOf(dValue);
|
||||||
|
}
|
||||||
|
else if (this.wrapTileText.doubleValue() < dValue)
|
||||||
|
this.wrapTileText = Double.valueOf(dValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,517 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
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.Parser;
|
||||||
|
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("O2CRS");
|
||||||
|
|
||||||
|
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
private final Parser parser = new Parser();
|
||||||
|
|
||||||
|
public O2CRSFactory() {
|
||||||
|
super(ReferencingFactoryContainer.instance(null), 99);
|
||||||
|
|
||||||
|
initCrsDefinitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
|
||||||
|
throws FactoryException
|
||||||
|
{
|
||||||
|
Set codes = new HashSet();
|
||||||
|
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
Iterator iter = this.definitions.keySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
String[] tempKeys = key.split("\\.");
|
||||||
|
|
||||||
|
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InternationalString getDescriptionText(String code)
|
||||||
|
throws NoSuchAuthorityCodeException, FactoryException
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = createCoordinateReferenceSystem(code);
|
||||||
|
return new SimpleInternationalString(crs.toWKT());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Citation getAuthority()
|
||||||
|
{
|
||||||
|
return this.authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code)
|
||||||
|
throws NoSuchAuthorityCodeException, FactoryException
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(code)) {
|
||||||
|
throw new FactoryException("CRS code is NULL.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] codes = code.split(":");
|
||||||
|
if (codes.length == 2)
|
||||||
|
{
|
||||||
|
SortedSet keys = new TreeSet(this.definitions.keySet());
|
||||||
|
Iterator iter = keys.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
String[] keyCodes = key.split("\\.");
|
||||||
|
|
||||||
|
if ((keyCodes[1].equalsIgnoreCase(codes[0].trim())) &&
|
||||||
|
(keyCodes[2].equalsIgnoreCase(codes[1].trim()))) {
|
||||||
|
return (CoordinateReferenceSystem)this.definitions.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (codes.length == 1)
|
||||||
|
{
|
||||||
|
SortedSet keys = new TreeSet(this.definitions.keySet());
|
||||||
|
Iterator iter = keys.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
String[] keyCodes = key.split("\\.");
|
||||||
|
|
||||||
|
if (keyCodes[2].equalsIgnoreCase(codes[0].trim()))
|
||||||
|
return (CoordinateReferenceSystem)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()
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
Statement st = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
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(auth)) ||
|
||||||
|
(ServerUtil.isNullString(code))) {
|
||||||
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (isContainSRID(srid))
|
||||||
|
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||||
|
if (isContainCRS(auth, code)) {
|
||||||
|
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinateReferenceSystem crs = parseWKT(auth, code, rs.getString("PARAMETER"));
|
||||||
|
this.definitions.put(srid + "." + auth + "." + code, crs);
|
||||||
|
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());
|
||||||
|
} finally {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ((ServerUtil.isNullString(auth)) || (ServerUtil.isNullString(code)))
|
||||||
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
|
if (ServerUtil.isNullString(wkt)) {
|
||||||
|
throw new FactoryException("CRS WKT is NULL.");
|
||||||
|
}
|
||||||
|
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
|
||||||
|
synchronized (this.parser) {
|
||||||
|
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAuthority(String auth)
|
||||||
|
{
|
||||||
|
Citation cit = Citations.fromName(auth);
|
||||||
|
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isContainAuthority(String auth)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
|
||||||
|
Iterator iter = this.authority.getIdentifiers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Identifier identifier = (Identifier)iter.next();
|
||||||
|
if (identifier.getCode().equalsIgnoreCase(auth)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isContainSRID(int srid)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (srid < 0) {
|
||||||
|
throw new FactoryException("SRID [" + srid + "] value is not available :: SRID >= 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this.definitions) {
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
|
||||||
|
Enumeration keys = this.definitions.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = (String)keys.nextElement();
|
||||||
|
|
||||||
|
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isContainCRS(String auth, String code)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(code)) {
|
||||||
|
throw new FactoryException("CODE is Null.");
|
||||||
|
}
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
|
||||||
|
synchronized (this.definitions) {
|
||||||
|
Enumeration keys = this.definitions.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = (String)keys.nextElement();
|
||||||
|
|
||||||
|
String[] codes = key.split("\\.");
|
||||||
|
if ((codes[1].equalsIgnoreCase(auth)) &&
|
||||||
|
(codes[2].equalsIgnoreCase(code))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCRSKey(int srid)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
synchronized (this.definitions) {
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
|
||||||
|
Enumeration keys = this.definitions.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = (String)keys.nextElement();
|
||||||
|
|
||||||
|
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (isContainSRID(srid))
|
||||||
|
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||||
|
if (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(" )");
|
||||||
|
|
||||||
|
executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
this.definitions.put(srid + "." + auth + "." + code, crs);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return st.execute(sql);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(auth)) {
|
||||||
|
throw new FactoryException("Authority value is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(code)) {
|
||||||
|
throw new FactoryException("Code value is Null.");
|
||||||
|
}
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (crs == null) {
|
||||||
|
throw new FactoryException("CRS value is Null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] ids = getCRSKey(srid).split("\\.");
|
||||||
|
if (((!ids[1].equals(auth)) || (!ids[2].equals(code))) && (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);
|
||||||
|
|
||||||
|
executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
String oldID = getCRSKey(srid);
|
||||||
|
this.definitions.remove(oldID);
|
||||||
|
|
||||||
|
this.definitions.put(srid + "." + auth + "." + code, crs);
|
||||||
|
|
||||||
|
addAuthority(auth);
|
||||||
|
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCRS(int srid, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (!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);
|
||||||
|
|
||||||
|
executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
|
||||||
|
Iterator iter = this.definitions.keySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
|
||||||
|
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
||||||
|
this.definitions.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem getCRS(int srid)
|
||||||
|
throws NoSuchAuthorityCodeException
|
||||||
|
{
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
|
||||||
|
SortedSet keys = new TreeSet(this.definitions.keySet());
|
||||||
|
Iterator iter = keys.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
|
||||||
|
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
||||||
|
return (CoordinateReferenceSystem)this.definitions.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAuthorityCodes(String auth)
|
||||||
|
{
|
||||||
|
TreeSet codes = new TreeSet();
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(auth))
|
||||||
|
{
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
Iterator iter = this.definitions.keySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
String[] tempKeys = key.split("\\.");
|
||||||
|
|
||||||
|
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
|
||||||
|
synchronized (this.definitions)
|
||||||
|
{
|
||||||
|
Iterator iter = this.definitions.keySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String key = (String)iter.next();
|
||||||
|
String[] tempKeys = key.split("\\.");
|
||||||
|
|
||||||
|
if (tempKeys[1].equalsIgnoreCase(auth)) {
|
||||||
|
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class Parser extends Parser {
|
||||||
|
private static final long serialVersionUID = -5910561042299146066L;
|
||||||
|
private CitationImpl auth;
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public Parser() {
|
||||||
|
super(O2CRSFactory.this.factories);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt)
|
||||||
|
throws ParseException
|
||||||
|
{
|
||||||
|
this.auth = new CitationImpl(Citations.fromName(auth));
|
||||||
|
this.code = code;
|
||||||
|
|
||||||
|
return super.parseCoordinateReferenceSystem(wkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> alterProperties(Map<String, Object> properties)
|
||||||
|
{
|
||||||
|
properties.put("identifiers", new NamedIdentifier(this.auth, this.code));
|
||||||
|
return super.alterProperties(properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,280 @@
|
||||||
|
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.Param;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.JDBCDataStoreFactory;
|
||||||
|
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;
|
||||||
|
|
||||||
|
refindParameter();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
InputStream in = new FileInputStream(sqlFile);
|
||||||
|
prop.load(in);
|
||||||
|
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(dbType.toLowerCase() + ".spatial.envelope"));
|
||||||
|
this.dsSQL.setSqlBBox(prop.getProperty(dbType.toLowerCase() + ".spatial.bbox"));
|
||||||
|
|
||||||
|
this.dsSQL.setGeomToWKB(prop.getProperty(dbType.toLowerCase() + ".geometry.to.wkb"));
|
||||||
|
this.dsSQL.setGeomFromWKB(prop.getProperty(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 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(new O2DSPrimaryKeyFinder(keyColumn));
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: " + keyColumn);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
dataStore.setPrimaryKeyFinder(new O2DSPrimaryKeyFinder("GID"));
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: GID");
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BasicDataSource createDataSource(Map params)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
BasicDataSource dataSource = new BasicDataSource();
|
||||||
|
|
||||||
|
dataSource.setDriverClassName(getDriverClassName());
|
||||||
|
|
||||||
|
dataSource.setUrl(getJDBCUrl(params));
|
||||||
|
|
||||||
|
String user = (String)USER.lookUp(params);
|
||||||
|
dataSource.setUsername(user);
|
||||||
|
|
||||||
|
String passwd = (String)PASSWD.lookUp(params);
|
||||||
|
if (passwd != null) {
|
||||||
|
dataSource.setPassword(passwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer minConn = (Integer)MINCONN.lookUp(params);
|
||||||
|
if (minConn != null) {
|
||||||
|
dataSource.setMinIdle(minConn.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer maxConn = (Integer)MAXCONN.lookUp(params);
|
||||||
|
if (maxConn != null) {
|
||||||
|
dataSource.setMaxActive(maxConn.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer maxWait = (Integer)MAXWAIT.lookUp(params);
|
||||||
|
if ((maxWait != null) && (maxWait.intValue() != -1)) {
|
||||||
|
dataSource.setMaxWait(maxWait.intValue() * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean validate = (Boolean)VALIDATECONN.lookUp(params);
|
||||||
|
if ((validate != null) && (validate.booleanValue()) && (getValidationQuery() != null)) {
|
||||||
|
dataSource.setTestOnBorrow(true);
|
||||||
|
dataSource.setValidationQuery(getValidationQuery());
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSource.setAccessToUnderlyingConnectionAllowed(true);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SQLDialect createSQLDialect(JDBCDataStore dataStore)
|
||||||
|
{
|
||||||
|
boolean useSpatial = true;
|
||||||
|
try {
|
||||||
|
useSpatial = ((Boolean)O2_USE_SPATIAL.lookUp(this.dsParams)).booleanValue();
|
||||||
|
|
||||||
|
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(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 getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getJDBCUrl(Map params) throws IOException
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return ConnMngr.getInstance().getConnObj(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 getTypeName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,290 @@
|
||||||
|
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.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.data.store.ContentDataStoreRefinder;
|
||||||
|
import org.geotools.data.store.ContentDataStore;
|
||||||
|
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.FilterFactory2;
|
||||||
|
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();
|
||||||
|
|
||||||
|
public static void putMemoryFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, Filter filter)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String key = layerType.toString() + "_" + serverName + "_" + tableName;
|
||||||
|
key = key.toUpperCase();
|
||||||
|
|
||||||
|
SpatialIndexFeatureSource featureSource = (SpatialIndexFeatureSource)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(collection);
|
||||||
|
|
||||||
|
memoryStore.put(key, featureSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearMemoryStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws IOException
|
||||||
|
{
|
||||||
|
String key = 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
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
JDBCFeatureStore featureStore;
|
||||||
|
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 = layerType.getType() + "_" + serverName + "_" + tableName;
|
||||||
|
key = key.toUpperCase();
|
||||||
|
|
||||||
|
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||||
|
if (featureSource != null) {
|
||||||
|
return featureSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
if (layerType == LayerFactory.LayerType.JDBC)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return JdbcStoreMngr.getDataStore(serverName).getFeatureSource(tableName);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
return ContentDataStoreRefinder.refindJDBCFeatureSource(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 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 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 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 = layerType.toString() + "_" + serverName + "_" + typeName;
|
||||||
|
key = key.toUpperCase();
|
||||||
|
|
||||||
|
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||||
|
if (featureSource != null) {
|
||||||
|
return getMemoryGmlObject(featureSource, id, hints);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
query.setHints(hints);
|
||||||
|
|
||||||
|
SimpleFeatureCollection features = featureSource.getFeatures(query);
|
||||||
|
if (!features.isEmpty()) {
|
||||||
|
SimpleFeatureIterator fi = features.features();
|
||||||
|
try {
|
||||||
|
if (fi.hasNext()) {
|
||||||
|
SimpleFeature localSimpleFeature = (SimpleFeature)fi.next(); return localSimpleFeature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fi.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,225 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,164 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,644 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,272 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,439 @@
|
||||||
|
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 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 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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
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.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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceExceptionElement.setTextContent(getMessage());
|
||||||
|
|
||||||
|
rootElement.appendChild(serviceExceptionElement);
|
||||||
|
|
||||||
|
if (ServerContext.isUseNSPrefix()) {
|
||||||
|
rootElement.setPrefix("ogc");
|
||||||
|
serviceExceptionElement.setPrefix("ogc");
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,720 @@
|
||||||
|
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 java.util.logging.Logger;
|
||||||
|
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.feature.type.GeometryType;
|
||||||
|
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();
|
||||||
|
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 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 = 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 localException1) {
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
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, null, cx);
|
||||||
|
|
||||||
|
return O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
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 = 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 = tableName.trim().toUpperCase() + "_" + columnName.trim().toUpperCase();
|
||||||
|
return (Integer)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 (OracleConnection)w.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 factory.createMultiPolygon(new Polygon[] { (Polygon)geom });
|
||||||
|
}
|
||||||
|
if ((targetClazz.equals(MultiPoint.class)) && ((geom instanceof Point))) {
|
||||||
|
return factory.createMultiPoint(new Point[] { (Point)geom });
|
||||||
|
}
|
||||||
|
if ((targetClazz.equals(MultiLineString.class)) && ((geom instanceof LineString))) {
|
||||||
|
return factory.createMultiLineString(new LineString[] { (LineString)geom });
|
||||||
|
}
|
||||||
|
if (targetClazz.equals(GeometryCollection.class)) {
|
||||||
|
return 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 = schemaName + ".";
|
||||||
|
}
|
||||||
|
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 (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT ");
|
||||||
|
|
||||||
|
encodeGeometryEnvelope(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(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, 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) {
|
||||||
|
if ((g instanceof LinearRing))
|
||||||
|
{
|
||||||
|
g = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNullSridGeometry(g)) {
|
||||||
|
srid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STRUCT struct = getStructFromGeometry(g, 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 localException)
|
||||||
|
{
|
||||||
|
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 localException1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, Hints hints, StringBuffer sql)
|
||||||
|
{
|
||||||
|
String sqlStr = "";
|
||||||
|
|
||||||
|
if (prefix != null) {
|
||||||
|
sqlStr = prefix + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlStr = 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,175 @@
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,192 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import javax.media.jai.InterpolationBicubic2;
|
||||||
|
import javax.media.jai.InterpolationBilinear;
|
||||||
|
import javax.media.jai.InterpolationNearest;
|
||||||
|
import javax.media.jai.JAI;
|
||||||
|
import org.geotools.data.DataStore;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
|
import org.geotools.data.crs.ForceCoordinateSystemFeatureReader;
|
||||||
|
import org.geotools.data.memory.MemoryDataStore;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.feature.NameImpl;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.map.GridCoverageLayer;
|
||||||
|
import org.geotools.map.MapContent;
|
||||||
|
import org.geotools.map.MapViewport;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.geotools.renderer.label.LabelCacheImpl.LabelRenderingMode;
|
||||||
|
import org.geotools.renderer.lite.StreamingRenderer;
|
||||||
|
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.StyledLayer;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
import org.geotools.styling.TextSymbolizer;
|
||||||
|
import org.geotools.styling.UserLayer;
|
||||||
|
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.Name;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
|
||||||
|
public class RenderMngr {
|
||||||
|
public static BufferedImage productMap(AVList params)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String[] layers = (String[])params.getValue("request.wms.layers");
|
||||||
|
String[] styles = (String[])params.getValue("request.wms.styles");
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)params.getValue("request.wms.sld");
|
||||||
|
|
||||||
|
Layer[] mapLayers = null;
|
||||||
|
|
||||||
|
if ((layers == null) || (layers.length == 0))
|
||||||
|
{
|
||||||
|
layers = null;
|
||||||
|
styles = null;
|
||||||
|
|
||||||
|
if (sld == null)
|
||||||
|
throw new IllegalArgumentException("Rendering parameter must have [LAYERS or (SLD, SLD_BODY)] value.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapLayers = new Layer[layers.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < layers.length; i++) {
|
||||||
|
if (ServerUtil.isNullString(layers[i])) {
|
||||||
|
throw new IllegalArgumentException("Layers parameter [" + layers[i] + "] is not available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(layers[i]);
|
||||||
|
if (mapLayer.getLayerType() == LayerFactory.LayerType.WCS) {
|
||||||
|
throw new IllegalArgumentException("Layer " + mapLayer.getName() + "(type:" + mapLayer.getLayerType() + ") is not support to render.");
|
||||||
|
}
|
||||||
|
|
||||||
|
mapLayers[i] = mapLayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((styles == null) || (styles.length == 0))
|
||||||
|
styles = new String[mapLayers.length];
|
||||||
|
else if (styles.length != mapLayers.length) {
|
||||||
|
throw new IllegalArgumentException("Parameter [LAYERS, STYLES] must configure the same length.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sld != null) {
|
||||||
|
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
||||||
|
sld.accept(sVisitor);
|
||||||
|
sld = (StyledLayerDescriptor)sVisitor.getCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||||
|
|
||||||
|
int width = params.getIntegerValue("request.wms.width", Integer.valueOf(256)).intValue();
|
||||||
|
int height = params.getIntegerValue("request.wms.height", Integer.valueOf(256)).intValue();
|
||||||
|
|
||||||
|
boolean transparent = params.getBooleanValue("request.wms.transparent", Boolean.valueOf(false)).booleanValue();
|
||||||
|
Color bgcolor = params.getColorValue("request.wms.bgcolor", Color.WHITE);
|
||||||
|
|
||||||
|
Rectangle paintArea = new Rectangle(0, 0, width, height);
|
||||||
|
|
||||||
|
ArrayList targetLayers = new ArrayList();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (mapLayers == null)
|
||||||
|
addRenderLayers(targetLayers, sld, params);
|
||||||
|
else if (sld == null)
|
||||||
|
addRenderLayers(targetLayers, mapLayers, styles, params);
|
||||||
|
else {
|
||||||
|
addRenderLayers(targetLayers, mapLayers, styles, sld, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
return drawImage(targetLayers, paintArea, bbox, bgcolor, transparent);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
targetLayers.clear();
|
||||||
|
targetLayers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, AVList params)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
for (int i = 0; i < layers.length; i++)
|
||||||
|
{
|
||||||
|
makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, StyledLayerDescriptor sld, AVList params)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
for (int i = 0; i < layers.length; i++)
|
||||||
|
{
|
||||||
|
ArrayList sldStyles = StyleMngr.getStylesFromSLD(layers[i].getName(), styles[i], sld);
|
||||||
|
if (sldStyles.isEmpty()) {
|
||||||
|
makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Iterator styleIter = sldStyles.iterator();
|
||||||
|
while (styleIter.hasNext()) {
|
||||||
|
Style tempStyle = (Style)styleIter.next();
|
||||||
|
|
||||||
|
if ((tempStyle instanceof NamedStyle))
|
||||||
|
makeNamedLayer(targetLayers, layers[i], tempStyle.getName(), params);
|
||||||
|
else
|
||||||
|
makeNamedLayer(targetLayers, layers[i], tempStyle, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
|
||||||
|
public class Request
|
||||||
|
{
|
||||||
|
private String service = "WMS";
|
||||||
|
private String version = null;
|
||||||
|
private String request = null;
|
||||||
|
private String baseURL = null;
|
||||||
|
private String format = "image/jpeg";
|
||||||
|
private Filter filter = null;
|
||||||
|
|
||||||
|
public String getService() {
|
||||||
|
return this.service;
|
||||||
|
}
|
||||||
|
public void setService(String service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
public String getVersion() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
public String getRequest() {
|
||||||
|
return this.request;
|
||||||
|
}
|
||||||
|
public void setRequest(String request) {
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
public String getBaseURL() {
|
||||||
|
return this.baseURL;
|
||||||
|
}
|
||||||
|
public void setBaseURL(String baseURL) {
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
}
|
||||||
|
public String getFormat() {
|
||||||
|
return this.format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
if (format.equals("image/jpg")) {
|
||||||
|
format = "image/jpeg";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
public Filter getFilter() {
|
||||||
|
return this.filter;
|
||||||
|
}
|
||||||
|
public void setFilter(Filter filter) {
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,50 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.geotools.se.v1_1.SE;
|
||||||
|
import org.geotools.se.v1_1.SEConfiguration;
|
||||||
|
import org.geotools.sld.v1_1.SLD;
|
||||||
|
import org.geotools.sld.v1_1.bindings.NamedLayerBinding;
|
||||||
|
import org.geotools.sld.v1_1.bindings.NamedStyleBinding;
|
||||||
|
import org.geotools.sld.v1_1.bindings.RemoteOWSBinding;
|
||||||
|
import org.geotools.sld.v1_1.bindings.UserLayerBinding;
|
||||||
|
import org.geotools.sld.v1_1.bindings.UserStyleBinding;
|
||||||
|
import org.geotools.styling.StyleFactory;
|
||||||
|
import org.geotools.xml.Configuration;
|
||||||
|
import org.geotools.xs.XS;
|
||||||
|
import org.picocontainer.MutablePicoContainer;
|
||||||
|
|
||||||
|
public class SLDConfiguration110 extends Configuration
|
||||||
|
{
|
||||||
|
public SLDConfiguration110()
|
||||||
|
{
|
||||||
|
super(SLD.getInstance());
|
||||||
|
|
||||||
|
addDependency(new SEConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerBindings(Map bindings)
|
||||||
|
{
|
||||||
|
bindings.put(SLD.StyledLayerDescriptor, StyledLayerDescriptorBinding110.class);
|
||||||
|
|
||||||
|
bindings.put(SLD.NamedLayer, NamedLayerBinding.class);
|
||||||
|
bindings.put(SLD.UserLayer, UserLayerBinding.class);
|
||||||
|
|
||||||
|
bindings.put(SLD.NamedStyle, NamedStyleBinding.class);
|
||||||
|
bindings.put(SLD.UserStyle, UserStyleBinding.class);
|
||||||
|
|
||||||
|
bindings.put(SLD.RemoteOWS, RemoteOWSBinding.class);
|
||||||
|
|
||||||
|
bindings.put(SE.Categorize, CategorizeBinding110.class);
|
||||||
|
bindings.put(SE.Interpolate, InterpolateBinding110.class);
|
||||||
|
|
||||||
|
bindings.put(XS.BOOLEAN, XSBooleanBinding110.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void configureContext(MutablePicoContainer container)
|
||||||
|
{
|
||||||
|
super.configureContext(container);
|
||||||
|
|
||||||
|
container.registerComponentImplementation(StyleFactory.class, O2StyleFactory.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,547 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.parsers.SAXParser;
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
public class ServerConfiguration
|
||||||
|
{
|
||||||
|
private static ServerConfiguration instance = null;
|
||||||
|
|
||||||
|
private HashMap<String, Object> confMap = null;
|
||||||
|
|
||||||
|
public static ServerConfiguration getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ServerConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean startServer()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.out.println("******************************");
|
||||||
|
System.out.println("Load server_conf.xml");
|
||||||
|
System.out.println("******************************");
|
||||||
|
|
||||||
|
loadConf();
|
||||||
|
System.out.println("Success :: Loading Configuration File :: WEB-INF/conf/server_conf.xml");
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
System.out.println("Fail :: Configuration Fil is not exist... :: " + e);
|
||||||
|
return false;
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
} catch (SAXException e) {
|
||||||
|
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Fail :: loading Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Fail :: can't access Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("******************************");
|
||||||
|
System.out.println("Init Logging Service");
|
||||||
|
System.out.println("******************************");
|
||||||
|
|
||||||
|
LogMngr.getInstance().initLog(this.confMap);
|
||||||
|
System.out.println("Success :: Starting Logging Service!!!");
|
||||||
|
|
||||||
|
if (LogMngr.getInstance().getLogDirctory() != null)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "Init log cache service");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "");
|
||||||
|
|
||||||
|
LogCacheManager.getInstance().start(this.confMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Fail :: Stop Logging Service..." + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Server loading... ");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "Check License");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
||||||
|
if (!LicenseMngr.checkLicense()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: License Not Availiable...");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
|
||||||
|
stopServer();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Initialize ServiceMap");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerContext.initMap(
|
||||||
|
(String)this.confMap.get("conf.xml.map.servicemap"),
|
||||||
|
(String)this.confMap.get("conf.xml.map.namespace"));
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: ServiceMap is not availiable. ::" + e.getMessage());
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
|
||||||
|
stopServer();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerContext.initLayers();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: Initializing Layer Fail ::" + e.getMessage());
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
|
||||||
|
stopServer();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Server Starting...");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopServer()
|
||||||
|
{
|
||||||
|
ServerContext.initOptions();
|
||||||
|
|
||||||
|
O2DSMngr.disposeStores();
|
||||||
|
|
||||||
|
ConnMngr connMngr = ConnMngr.getInstance();
|
||||||
|
connMngr.closeConn();
|
||||||
|
|
||||||
|
LogCacheManager.getInstance().stop();
|
||||||
|
|
||||||
|
RenderMngr.disposeRenderingPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void loadConf()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (this.confMap == null)
|
||||||
|
this.confMap = new HashMap();
|
||||||
|
else {
|
||||||
|
this.confMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerContext.initOptions();
|
||||||
|
|
||||||
|
File confFile = new File(ServerContext.getConfFolder(), "/server_conf.xml");
|
||||||
|
|
||||||
|
System.out.println("Configuration File Location :: " + confFile.getAbsolutePath());
|
||||||
|
|
||||||
|
if (confFile.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Now try parse Configuration File");
|
||||||
|
|
||||||
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
SAXParser parser = factory.newSAXParser();
|
||||||
|
ConfParserHandler handler = new ConfParserHandler();
|
||||||
|
parser.parse(confFile, handler);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new FileNotFoundException("Configuration File is not exist [" + confFile.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getMapList()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
HashSet mapList = new HashSet();
|
||||||
|
|
||||||
|
Connection connection = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
connection = ConnMngr.getInstance().openConn();
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
|
||||||
|
String sql = "SELECT MAP_NAME FROM O2MAP_SERVICE_INFO";
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Load MapList :: SQL > " + sql);
|
||||||
|
rs = stmt.executeQuery(sql);
|
||||||
|
|
||||||
|
if (rs != null) {
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
String mapName = rs.getString(1);
|
||||||
|
if (ServerUtil.isNullString(mapName)) {
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Skip this layer :: MAP_NAME is NULL");
|
||||||
|
}
|
||||||
|
else if (mapList.add(mapName.trim().toUpperCase())) {
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]",
|
||||||
|
"Add MAP_NAME [" + mapList.size() + "/" + mapName.trim().toUpperCase() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapList.size() == 0) {
|
||||||
|
throw new Exception("Map Count is [0]");
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]",
|
||||||
|
"Success to load MapList :: Map Count is [" + mapList.size() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[MAP]",
|
||||||
|
"Fail to load MapList :: " + e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> getConfMap()
|
||||||
|
{
|
||||||
|
return this.confMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfParserHandler extends DefaultHandler
|
||||||
|
{
|
||||||
|
boolean isServer = false;
|
||||||
|
|
||||||
|
boolean isMap = false;
|
||||||
|
boolean isDbtype = false;
|
||||||
|
boolean isHost = false;
|
||||||
|
boolean isPort = false;
|
||||||
|
boolean isDatabase = false;
|
||||||
|
boolean isUser = false;
|
||||||
|
boolean isPasswd = false;
|
||||||
|
boolean isServicemap = false;
|
||||||
|
|
||||||
|
boolean isOption = false;
|
||||||
|
boolean isNamespace = false;
|
||||||
|
boolean isUseNS = false;
|
||||||
|
boolean isDocIndent = false;
|
||||||
|
boolean isDefaultMaxFeatures = false;
|
||||||
|
boolean isEncryption = false;
|
||||||
|
|
||||||
|
boolean isLog = false;
|
||||||
|
boolean isLogDir = false;
|
||||||
|
boolean isLogLevel = false;
|
||||||
|
boolean isLogRequest = false;
|
||||||
|
boolean isLogCache = false;
|
||||||
|
boolean isLogCacheType = false;
|
||||||
|
boolean isLogCacheValue = false;
|
||||||
|
|
||||||
|
boolean isAdmin = false;
|
||||||
|
boolean isSecure_key = false;
|
||||||
|
boolean isStyle_key = false;
|
||||||
|
|
||||||
|
ConfParserHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if (this.isServer)
|
||||||
|
{
|
||||||
|
if (this.isMap)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("DBTYPE")) {
|
||||||
|
this.isDbtype = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("HOST")) {
|
||||||
|
this.isHost = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("PORT")) {
|
||||||
|
this.isPort = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DATABASE")) {
|
||||||
|
this.isDatabase = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("USER")) {
|
||||||
|
this.isUser = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("PASSWD")) {
|
||||||
|
this.isPasswd = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
||||||
|
this.isServicemap = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("OPTION")) {
|
||||||
|
this.isOption = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
||||||
|
this.isNamespace = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("USENS")) {
|
||||||
|
this.isUseNS = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
||||||
|
this.isDocIndent = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
||||||
|
this.isDefaultMaxFeatures = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
||||||
|
this.isEncryption = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isLog)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("DIR")) {
|
||||||
|
this.isLogDir = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("LEVEL")) {
|
||||||
|
this.isLogLevel = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("REQUEST")) {
|
||||||
|
this.isLogRequest = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("CACHE")) {
|
||||||
|
this.isLogCache = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("TYPE")) {
|
||||||
|
this.isLogCacheType = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("VALUE")) {
|
||||||
|
this.isLogCacheValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isAdmin)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
||||||
|
this.isSecure_key = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
||||||
|
this.isStyle_key = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equalsIgnoreCase("MAP")) {
|
||||||
|
this.isMap = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("LOG")) {
|
||||||
|
this.isLog = true;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("ADMIN")) {
|
||||||
|
this.isAdmin = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equalsIgnoreCase("SERVER"))
|
||||||
|
this.isServer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endElement(String uri, String localName, String qName)
|
||||||
|
throws SAXException
|
||||||
|
{
|
||||||
|
if (this.isServer)
|
||||||
|
{
|
||||||
|
if (this.isMap)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("DBTYPE")) {
|
||||||
|
this.isDbtype = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("HOST")) {
|
||||||
|
this.isHost = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("PORT")) {
|
||||||
|
this.isPort = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DATABASE")) {
|
||||||
|
this.isDatabase = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("USER")) {
|
||||||
|
this.isUser = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("PASSWD")) {
|
||||||
|
this.isPasswd = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
||||||
|
this.isServicemap = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("OPTION")) {
|
||||||
|
this.isOption = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
||||||
|
this.isNamespace = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("USENS")) {
|
||||||
|
this.isUseNS = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
||||||
|
this.isDocIndent = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
||||||
|
this.isDefaultMaxFeatures = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
||||||
|
this.isEncryption = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isLog)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("DIR")) {
|
||||||
|
this.isLogDir = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("LEVEL")) {
|
||||||
|
this.isLogLevel = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("REQUEST")) {
|
||||||
|
this.isLogRequest = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("CACHE")) {
|
||||||
|
this.isLogCache = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("TYPE")) {
|
||||||
|
this.isLogCacheType = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("VALUE")) {
|
||||||
|
this.isLogCacheValue = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isAdmin)
|
||||||
|
{
|
||||||
|
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
||||||
|
this.isSecure_key = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
||||||
|
this.isStyle_key = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equalsIgnoreCase("MAP")) {
|
||||||
|
this.isMap = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("LOG")) {
|
||||||
|
this.isLog = false;
|
||||||
|
}
|
||||||
|
else if (qName.equalsIgnoreCase("ADMIN")) {
|
||||||
|
this.isAdmin = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equalsIgnoreCase("SERVER"))
|
||||||
|
this.isServer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void characters(char[] ch, int start, int length)
|
||||||
|
throws SAXException
|
||||||
|
{
|
||||||
|
if (this.isServer)
|
||||||
|
{
|
||||||
|
if (this.isMap)
|
||||||
|
{
|
||||||
|
if (this.isDbtype) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.dbtype", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isHost) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.host", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isPort) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.port", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isDatabase) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.database", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isUser) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.user", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isPasswd) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.passwd", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isServicemap) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.servicemap", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isNamespace) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.namespace", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isUseNS) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.usedefaultnsprefix", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isDocIndent) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.docindent", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isDefaultMaxFeatures) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.default.max.features", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isEncryption) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.encryption", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isLog)
|
||||||
|
{
|
||||||
|
if (this.isLogDir) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.dir", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isLogLevel) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.level", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isLogRequest) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.request", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isLogCacheType) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.cache.type", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isLogCacheValue) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.cache.value", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.isAdmin)
|
||||||
|
{
|
||||||
|
if (this.isSecure_key) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.admin.secure.key", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
else if (this.isStyle_key)
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.admin.style.key", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,575 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class ServerContext
|
||||||
|
{
|
||||||
|
private static Map serviceMap;
|
||||||
|
private static String CONF_FOLDER_NAME = "/conf";
|
||||||
|
private static File confFolder = null;
|
||||||
|
|
||||||
|
private static String STYLES_FOLDER_NAME = "/styles";
|
||||||
|
private static File stylesFolder;
|
||||||
|
private static String PLUGINS_FOLDER_NAME = "/plugins";
|
||||||
|
private static File pluginsFolder;
|
||||||
|
private static Integer docIndent = null;
|
||||||
|
private static Boolean useNSPrefix = null;
|
||||||
|
private static Integer defaultMaxFeatures = null;
|
||||||
|
private static Boolean encryption = null;
|
||||||
|
|
||||||
|
public static void initMap(String mapName, String nameSpace)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(mapName)) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"ServiceMap Name is NULL. Now set default [O2MAP].");
|
||||||
|
mapName = "O2MAP";
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceMap = new Map(mapName, nameSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void changeMap(String mapName, String nameSpace)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(mapName)) {
|
||||||
|
throw new NullPointerException("Parameter [ServiceMap] is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Get MapList");
|
||||||
|
HashSet mapList = ServerConfiguration.getInstance().getMapList();
|
||||||
|
if (!mapList.contains(mapName.trim().toUpperCase())) {
|
||||||
|
throw new NullPointerException("Parameter [ServiceMap:" + mapName + "] is not exist in ServiceMap List.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(nameSpace)) {
|
||||||
|
nameSpace = serviceMap.getNameSpaceURI();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((serviceMap.getName().equalsIgnoreCase(mapName)) &&
|
||||||
|
(serviceMap.getNameSpaceURI().equalsIgnoreCase(nameSpace))) {
|
||||||
|
throw new IllegalArgumentException("Parameter [ServiceMap:" + mapName + "] is current Map.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map dirtyMap = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerInfo.getInstance().setReStarting(true);
|
||||||
|
|
||||||
|
dirtyMap = serviceMap;
|
||||||
|
serviceMap = new Map(mapName, nameSpace);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Create Service Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "-----------------------------------");
|
||||||
|
initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
serviceMap = dirtyMap;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
dirtyMap = null;
|
||||||
|
ServerInfo.getInstance().setReStarting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map getMap()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (serviceMap == null) {
|
||||||
|
throw new NullPointerException("ServiceMap is NULL.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initLayers()
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Create JDBC Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
JdbcStoreMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "Create GeoWave Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||||
|
GWaveStoreMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Create Shape Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||||
|
ShpStoreMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "Create WMTS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||||
|
|
||||||
|
WMTSMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "Create TMS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||||
|
|
||||||
|
TMSMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Create ImgCache Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||||
|
|
||||||
|
ImgCacheMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "Create O2Img Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||||
|
|
||||||
|
O2ImgLayerMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "Create O2Dem Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||||
|
|
||||||
|
O2DemLayerMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "Create O2WPS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||||
|
|
||||||
|
WpsVecStoreMngr.initLayers();
|
||||||
|
WpsCovStoreMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadLayers()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerInfo.getInstance().setReStarting(true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Relaod JDBC Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
|
|
||||||
|
JdbcStoreMngr.reloadLayer();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Success to reload JDBC Layer");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Fail to reload JDBC Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "Relaod GeoWave Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||||
|
|
||||||
|
GWaveStoreMngr.reloadLayer();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "Success to reload GeoWave Layer");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "Fail to reload GeoWave Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[GWAVE]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Relaod Shape Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||||
|
|
||||||
|
ShpStoreMngr.reloadLayer();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Success to reload Shape Layer");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Fail to reload Shape Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "Relaod WMTS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||||
|
|
||||||
|
WMTSMngr.reloadLayer();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "Fail to reload WMTS Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[WMTS]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "Relaod TMS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||||
|
|
||||||
|
TMSMngr.reloadLayer();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "Fail to reload TMS Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Relaod ImgCache Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||||
|
|
||||||
|
ImgCacheMngr.reloadLayer();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Fail to reload ImgCache Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "Relaod O2Img Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||||
|
|
||||||
|
O2ImgLayerMngr.reloadLayer();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "Fail to reload O2Img Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "Relaod O2Dem Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||||
|
|
||||||
|
O2DemLayerMngr.reloadLayer();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "Fail to reload O2Dem Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "Relaod O2WPS Layer");
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||||
|
|
||||||
|
WpsVecStoreMngr.reloadLayer();
|
||||||
|
WpsCovStoreMngr.reloadLayer();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "Success to reload O2WPS Layer");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "Fail to reload O2WPS Layer :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ServerInfo.getInstance().setReStarting(false);
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadStyle(String layerName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerInfo.getInstance().setReStarting(true);
|
||||||
|
|
||||||
|
if (layerName != null) {
|
||||||
|
layerName = layerName.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList layers = getMap().getAllLayers();
|
||||||
|
for (Layer layer : layers)
|
||||||
|
{
|
||||||
|
if ((layerName == null) ||
|
||||||
|
(layerName.equalsIgnoreCase(layer.getName())))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ((layer instanceof FeatureLayer))
|
||||||
|
((FeatureLayer)layer).reloadServiceStyle();
|
||||||
|
else if ((layer instanceof O2DemLayer)) {
|
||||||
|
((O2DemLayer)layer).reloadServiceStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Success to reload Style for this layer [" + layer.getName() + "]");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Fail to reload Style for this layer [" + layer.getName() + "] :: " + e);
|
||||||
|
} finally {
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ServerInfo.getInstance().setReStarting(false);
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getWebInfFolder()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
URL url = ServerContext.class.getResource("/");
|
||||||
|
return new File(url.toURI()).getParentFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getConfFolder()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (confFolder == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
confFolder = new File(getWebInfFolder(), CONF_FOLDER_NAME);
|
||||||
|
|
||||||
|
if (!confFolder.exists()) {
|
||||||
|
confFolder.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
confFolder.setReadable(true, false);
|
||||||
|
confFolder.setWritable(true, false);
|
||||||
|
}
|
||||||
|
catch (SecurityException e) {
|
||||||
|
throw new SecurityException("Folder [WEB-INF" + CONF_FOLDER_NAME + "] is not accessible.", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
confFolder = null;
|
||||||
|
throw new Exception("Folder [WEB-INF" + CONF_FOLDER_NAME + "] has problem.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return confFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File setConfFolder(File path) throws Exception {
|
||||||
|
if ((path == null) ||
|
||||||
|
(!path.exists()) ||
|
||||||
|
(path.isFile())) {
|
||||||
|
throw new IOException("Conf Folder is not exist.");
|
||||||
|
}
|
||||||
|
confFolder = path;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getStylesFolder() throws Exception
|
||||||
|
{
|
||||||
|
if (stylesFolder == null) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stylesFolder = new File(getWebInfFolder(), STYLES_FOLDER_NAME);
|
||||||
|
|
||||||
|
if (!stylesFolder.exists()) {
|
||||||
|
stylesFolder.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
stylesFolder.setReadable(true, false);
|
||||||
|
stylesFolder.setWritable(true, false);
|
||||||
|
}
|
||||||
|
catch (SecurityException e) {
|
||||||
|
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + STYLES_FOLDER_NAME + "] is not accessible.");
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
stylesFolder = null;
|
||||||
|
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + STYLES_FOLDER_NAME + "] has problem.");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return stylesFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File setStylesFolder(File path) throws Exception {
|
||||||
|
if ((path == null) ||
|
||||||
|
(!path.exists()) ||
|
||||||
|
(path.isFile())) {
|
||||||
|
throw new IOException("Styles Folder is not exist.");
|
||||||
|
}
|
||||||
|
stylesFolder = path;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getPluginsFolder() throws Exception
|
||||||
|
{
|
||||||
|
if (pluginsFolder == null) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pluginsFolder = new File(getWebInfFolder(), PLUGINS_FOLDER_NAME);
|
||||||
|
|
||||||
|
if (!pluginsFolder.exists()) {
|
||||||
|
pluginsFolder.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginsFolder.setReadable(true, false);
|
||||||
|
pluginsFolder.setWritable(true, false);
|
||||||
|
}
|
||||||
|
catch (SecurityException e) {
|
||||||
|
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + PLUGINS_FOLDER_NAME + "] is not accessible.");
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
pluginsFolder = null;
|
||||||
|
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + PLUGINS_FOLDER_NAME + "] has problem.");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return pluginsFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File setPluginsFolder(File path) throws Exception {
|
||||||
|
if ((path == null) ||
|
||||||
|
(!path.exists()) ||
|
||||||
|
(path.isFile())) {
|
||||||
|
throw new IOException("Plugins Folder is not exist.");
|
||||||
|
}
|
||||||
|
pluginsFolder = path;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initOptions()
|
||||||
|
{
|
||||||
|
docIndent = null;
|
||||||
|
useNSPrefix = null;
|
||||||
|
defaultMaxFeatures = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getDocIndent()
|
||||||
|
{
|
||||||
|
if (docIndent == null)
|
||||||
|
{
|
||||||
|
String indent = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.docindent");
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(indent)) {
|
||||||
|
docIndent = Integer.valueOf(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
double value = Double.parseDouble(indent);
|
||||||
|
docIndent = Integer.valueOf((int)value);
|
||||||
|
|
||||||
|
if (docIndent.intValue() < 0)
|
||||||
|
docIndent = Integer.valueOf(0);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
docIndent = Integer.valueOf(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return docIndent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUseNSPrefix()
|
||||||
|
{
|
||||||
|
if (useNSPrefix == null)
|
||||||
|
{
|
||||||
|
String useNS = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.usedefaultnsprefix");
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(useNS))
|
||||||
|
useNSPrefix = Boolean.valueOf(true);
|
||||||
|
else {
|
||||||
|
useNSPrefix = Boolean.valueOf(ServerUtil.getBooleanValue(useNS));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return useNSPrefix.booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getDefaultMaxFeatrues()
|
||||||
|
{
|
||||||
|
if (defaultMaxFeatures == null)
|
||||||
|
{
|
||||||
|
String defaultValue = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.default.max.features");
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(defaultValue)) {
|
||||||
|
defaultMaxFeatures = Integer.valueOf(10000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
defaultMaxFeatures = Integer.valueOf(defaultValue.trim());
|
||||||
|
|
||||||
|
if (defaultMaxFeatures.intValue() <= 0) {
|
||||||
|
defaultMaxFeatures = Integer.valueOf(2147483647);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
defaultMaxFeatures = Integer.valueOf(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultMaxFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEncryption()
|
||||||
|
{
|
||||||
|
if (encryption == null)
|
||||||
|
{
|
||||||
|
String useEncryption = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.encryption");
|
||||||
|
|
||||||
|
if (ServerUtil.isNullString(useEncryption))
|
||||||
|
encryption = Boolean.valueOf(false);
|
||||||
|
else {
|
||||||
|
encryption = Boolean.valueOf(ServerUtil.getBooleanValue(useEncryption));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return encryption.booleanValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class ServerInfo
|
||||||
|
{
|
||||||
|
private static ServerInfo instance = null;
|
||||||
|
|
||||||
|
private boolean isStarted = false;
|
||||||
|
private boolean isReStarting = false;
|
||||||
|
|
||||||
|
public static ServerInfo getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ServerInfo();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStarted()
|
||||||
|
{
|
||||||
|
return this.isStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStarted(boolean isStarted) {
|
||||||
|
this.isStarted = isStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReStarting() {
|
||||||
|
return this.isReStarting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReStarting(boolean isReStarting) {
|
||||||
|
this.isReStarting = isReStarting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,396 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
|
||||||
|
public class ServerUtil
|
||||||
|
{
|
||||||
|
public static boolean isNullString(String str)
|
||||||
|
{
|
||||||
|
if ((str == null) || (str.trim().equals(""))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getStringArray(String str, String regex)
|
||||||
|
{
|
||||||
|
if (isNullString(str)) return null;
|
||||||
|
|
||||||
|
String[] strArray = str.split(regex);
|
||||||
|
|
||||||
|
ArrayList resultList = new ArrayList();
|
||||||
|
for (String val : strArray) {
|
||||||
|
if (!isNullString(val)) {
|
||||||
|
resultList.add(val.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (String[])resultList.toArray(new String[resultList.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double[] getDoubleArray(String str, String regex)
|
||||||
|
{
|
||||||
|
if (isNullString(str)) return null;
|
||||||
|
|
||||||
|
String[] strArray = str.split(regex);
|
||||||
|
|
||||||
|
ArrayList resultList = new ArrayList();
|
||||||
|
for (String val : strArray) {
|
||||||
|
if (!isNullString(val)) {
|
||||||
|
try {
|
||||||
|
resultList.add(Double.valueOf(Double.parseDouble(val.trim())));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Double[])resultList.toArray(new Double[resultList.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHexFromColor(Color color) {
|
||||||
|
try {
|
||||||
|
return String.format("#%02x%02x%02x", new Object[] { Integer.valueOf(color.getRed()), Integer.valueOf(color.getGreen()), Integer.valueOf(color.getBlue()) });
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHexFromColor(Color color, int alpha) {
|
||||||
|
try {
|
||||||
|
return String.format("#%02x%02x%02x%02x", new Object[] { Integer.valueOf(color.getRed()), Integer.valueOf(color.getGreen()), Integer.valueOf(color.getBlue()), Integer.valueOf(alpha) });
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color getColorFromHex(String hex)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (hex.startsWith("#")) {
|
||||||
|
hex = hex.replaceFirst("#", "0x");
|
||||||
|
}
|
||||||
|
|
||||||
|
Color color = null;
|
||||||
|
if (hex.length() == 10) {
|
||||||
|
color = new Color(
|
||||||
|
Integer.valueOf(hex.substring(2, 4), 16).intValue(),
|
||||||
|
Integer.valueOf(hex.substring(4, 6), 16).intValue(),
|
||||||
|
Integer.valueOf(hex.substring(6, 8), 16).intValue(),
|
||||||
|
Integer.valueOf(hex.substring(8, 10), 16).intValue());
|
||||||
|
}
|
||||||
|
return new Color(
|
||||||
|
Integer.valueOf(hex.substring(2, 4), 16).intValue(),
|
||||||
|
Integer.valueOf(hex.substring(4, 6), 16).intValue(),
|
||||||
|
Integer.valueOf(hex.substring(6, 8), 16).intValue(),
|
||||||
|
255);
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] cloneInputStream(InputStream is)
|
||||||
|
{
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
while ((len = is.read(buffer)) > -1)
|
||||||
|
{
|
||||||
|
baos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
baos.flush();
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (baos != null) {
|
||||||
|
baos.close();
|
||||||
|
baos = null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
baos = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStringOption(Symbolizer symbolizer, String optionName, String defaultValue) {
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double getDoubleOption(Symbolizer symbolizer, String optionName, Double defaultValue) {
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
if (value == null)
|
||||||
|
return defaultValue;
|
||||||
|
try {
|
||||||
|
return Double.valueOf(Double.parseDouble(value)); } catch (Exception e) {
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getBooleanOption(Symbolizer symbolizer, String optionName, Boolean defaultValue)
|
||||||
|
{
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if ((!value.equalsIgnoreCase("yes")) && (!value.equalsIgnoreCase("true")) && (!value.equalsIgnoreCase("1")) && (!value.equalsIgnoreCase("Y"))) return Boolean.valueOf(false); return Boolean.valueOf(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getIntegerOption(Symbolizer symbolizer, String optionName, Integer defaultValue) {
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
if (value == null)
|
||||||
|
return defaultValue;
|
||||||
|
try {
|
||||||
|
return Integer.valueOf(Integer.parseInt(value)); } catch (Exception e) {
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Enum<T>> Enum<T> getEnumOption(Symbolizer symbolizer, String optionName, Enum<T> defaultValue)
|
||||||
|
{
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
|
||||||
|
if (value == null)
|
||||||
|
return defaultValue;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(defaultValue.getDeclaringClass(), value.toUpperCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] getGraphicMarginOption(Symbolizer symbolizer, String optionName, int defaultValue)
|
||||||
|
{
|
||||||
|
String value = getOptionValue(symbolizer.getOptions(), optionName);
|
||||||
|
if (value == null) {
|
||||||
|
return new int[] { defaultValue, defaultValue, defaultValue, defaultValue };
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] values = new String[0];
|
||||||
|
if (value.contains(","))
|
||||||
|
values = value.trim().split(",");
|
||||||
|
else {
|
||||||
|
values = value.trim().split("\\s+");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((values.length == 0) || (values.length > 4)) {
|
||||||
|
return new int[] { defaultValue, defaultValue, defaultValue, defaultValue };
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] parsed = new int[values.length];
|
||||||
|
boolean allZeroMargin = false;
|
||||||
|
for (int i = 0; i < parsed.length; i++) {
|
||||||
|
try {
|
||||||
|
int margin = Integer.parseInt(values[i].trim());
|
||||||
|
allZeroMargin = (allZeroMargin) && (margin == 0);
|
||||||
|
parsed[i] = margin;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new int[] { defaultValue, defaultValue, defaultValue, defaultValue };
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allZeroMargin)
|
||||||
|
return new int[] { defaultValue, defaultValue, defaultValue, defaultValue };
|
||||||
|
if (parsed.length == 4)
|
||||||
|
return parsed;
|
||||||
|
if (parsed.length == 3)
|
||||||
|
return new int[] { parsed[0], parsed[1], parsed[2], parsed[1] };
|
||||||
|
if (parsed.length == 2) {
|
||||||
|
return new int[] { parsed[0], parsed[1], parsed[0], parsed[1] };
|
||||||
|
}
|
||||||
|
return new int[] { parsed[0], parsed[0], parsed[0], parsed[0] };
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getOptionValue(Map<String, String> map, String key)
|
||||||
|
{
|
||||||
|
Iterator mapKeys = map.keySet().iterator();
|
||||||
|
while (mapKeys.hasNext()) {
|
||||||
|
String mapKey = (String)mapKeys.next();
|
||||||
|
if (mapKey.equalsIgnoreCase(key)) {
|
||||||
|
return (String)map.get(mapKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getBooleanValue(String str)
|
||||||
|
{
|
||||||
|
if (isNullString(str)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = str.trim();
|
||||||
|
|
||||||
|
if ((str.equalsIgnoreCase("YES")) ||
|
||||||
|
(str.equalsIgnoreCase("TRUE")) ||
|
||||||
|
(str.equalsIgnoreCase("1")) ||
|
||||||
|
(str.equalsIgnoreCase("Y"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileExtension(File file)
|
||||||
|
{
|
||||||
|
String name = file.getName();
|
||||||
|
int lastIndexOf = name.lastIndexOf(".");
|
||||||
|
if (lastIndexOf == -1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return name.substring(lastIndexOf + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileName(File file) {
|
||||||
|
String name = file.getName();
|
||||||
|
int lastIndexOf = name.lastIndexOf(".");
|
||||||
|
if (lastIndexOf == -1) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
return name.substring(0, lastIndexOf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceFirst(String str, String match, String target)
|
||||||
|
{
|
||||||
|
StringBuffer strBuffer = new StringBuffer(str);
|
||||||
|
if (str.contains(match))
|
||||||
|
{
|
||||||
|
int start = str.indexOf(match);
|
||||||
|
|
||||||
|
strBuffer.replace(start, start + match.length(), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Properties getPropertiesFromFile(File textFile, String sep)
|
||||||
|
{
|
||||||
|
Properties properties = new Properties();
|
||||||
|
|
||||||
|
if (textFile.exists())
|
||||||
|
{
|
||||||
|
BufferedReader bReader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bReader = new BufferedReader(new FileReader(textFile));
|
||||||
|
String line;
|
||||||
|
while ((line = bReader.readLine()) != null) {
|
||||||
|
line = line.trim();
|
||||||
|
if ((!line.startsWith("#")) && (!isNullString(line)))
|
||||||
|
{
|
||||||
|
String[] params = line.split("\\" + sep);
|
||||||
|
if ((params.length == 2) &&
|
||||||
|
(!isNullString(params[0])) &&
|
||||||
|
(!isNullString(params[1])))
|
||||||
|
{
|
||||||
|
properties.put(params[0].trim().toLowerCase(), params[1].trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) { LogMngr.getInstance().logError("[FILE]", "Properties file is not valid :: " + e.getMessage());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File findFile(File rootDir, final String fileName) { // fileName을 final로 선언
|
||||||
|
File[] files = rootDir.listFiles(new FilenameFilter() {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
// 전달받은 fileName과 현재 파일의 이름을 대소문자 구분 없이 비교
|
||||||
|
if (name.toUpperCase().equals(fileName.toUpperCase())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (files.length == 1) {
|
||||||
|
return files[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeFile(File file, boolean isRoot) {
|
||||||
|
if (file.isFile()) {
|
||||||
|
file.delete();
|
||||||
|
} else {
|
||||||
|
for (File subFile : file.listFiles()) {
|
||||||
|
removeFile(subFile, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isRoot)
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rectangle calPaintArea(Rectangle area, Envelope pBBox, Envelope cBBox)
|
||||||
|
{
|
||||||
|
double ulScaleX = (cBBox.getMinX() - pBBox.getMinX()) / pBBox.getWidth();
|
||||||
|
double ulScaleY = (pBBox.getMaxY() - cBBox.getMaxY()) / pBBox.getHeight();
|
||||||
|
|
||||||
|
double lrScaleX = (cBBox.getMaxX() - pBBox.getMinX()) / pBBox.getWidth();
|
||||||
|
double lrScaleY = (pBBox.getMaxY() - cBBox.getMinY()) / pBBox.getHeight();
|
||||||
|
|
||||||
|
int pointX = (int)Math.round(area.getWidth() * ulScaleX);
|
||||||
|
int pointY = (int)Math.round(area.getHeight() * ulScaleY);
|
||||||
|
int width = (int)Math.round(area.getWidth() * lrScaleX - pointX);
|
||||||
|
int height = (int)Math.round(area.getHeight() * lrScaleY - pointY);
|
||||||
|
|
||||||
|
return new Rectangle(pointX, pointY, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class SimpleSql
|
||||||
|
{
|
||||||
|
public final String KEY_GEOMTRY = "?GEOMETRY?";
|
||||||
|
public final String KEY_WKB = "?WKB?";
|
||||||
|
public final String KEY_SRID = "?SRID?";
|
||||||
|
private final String dbType;
|
||||||
|
private String sqlEnvelope;
|
||||||
|
private String sqlBBox;
|
||||||
|
private String geomToWKB;
|
||||||
|
private String geomFromWKB;
|
||||||
|
|
||||||
|
public SimpleSql(String type)
|
||||||
|
{
|
||||||
|
this.dbType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDbType() {
|
||||||
|
return this.dbType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSqlEnvelope() {
|
||||||
|
return this.sqlEnvelope;
|
||||||
|
}
|
||||||
|
public String getSqlBBox() {
|
||||||
|
return this.sqlBBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeomToWKB() {
|
||||||
|
return this.geomToWKB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeomFromWKB() {
|
||||||
|
return this.geomFromWKB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSqlEnvelope(String envelope) {
|
||||||
|
this.sqlEnvelope = envelope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSqlBBox(String bbox) {
|
||||||
|
this.sqlBBox = bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeomToWKB(String toWKB) {
|
||||||
|
this.geomToWKB = toWKB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeomFromWKB(String fromWKB) {
|
||||||
|
this.geomFromWKB = fromWKB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidate() {
|
||||||
|
if (this.dbType == null) return false;
|
||||||
|
|
||||||
|
if (this.sqlEnvelope == null) return false;
|
||||||
|
if (this.sqlBBox == null) return false;
|
||||||
|
|
||||||
|
if (this.geomToWKB == null) return false;
|
||||||
|
if (this.geomFromWKB == null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
sb.append("[ ");
|
||||||
|
sb.append("dbType : ").append(this.dbType).append(" , ");
|
||||||
|
sb.append("spatial.envelope : ").append(this.sqlEnvelope).append(" , ");
|
||||||
|
sb.append("spatial.bbox : ").append(this.sqlBBox).append(" , ");
|
||||||
|
sb.append("geometry.to.wkb : ").append(this.geomToWKB).append(" , ");
|
||||||
|
sb.append("geometry.from.wkb : ").append(this.geomFromWKB);
|
||||||
|
sb.append(" ]");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,516 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.Rectangle2D.Double;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.factory.GeoTools;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.renderer.style.MarkStyle2D;
|
||||||
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
|
import org.geotools.styling.Fill;
|
||||||
|
import org.geotools.styling.Graphic;
|
||||||
|
import org.geotools.styling.Mark;
|
||||||
|
import org.geotools.styling.NamedLayer;
|
||||||
|
import org.geotools.styling.RasterSymbolizerImpl;
|
||||||
|
import org.geotools.styling.Rule;
|
||||||
|
import org.geotools.styling.SLDTransformer;
|
||||||
|
import org.geotools.styling.ShadedReliefImpl;
|
||||||
|
import org.geotools.styling.Stroke;
|
||||||
|
import org.geotools.styling.Style;
|
||||||
|
import org.geotools.styling.StyleBuilder;
|
||||||
|
import org.geotools.styling.StyleFactory;
|
||||||
|
import org.geotools.styling.StyledLayer;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
import org.geotools.styling.UserLayer;
|
||||||
|
import org.geotools.xml.Parser;
|
||||||
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.geom.Rectangle2D.Double;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.factory.GeoTools;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.renderer.style.MarkStyle2D;
|
||||||
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
|
import org.geotools.styling.Fill;
|
||||||
|
import org.geotools.styling.Graphic;
|
||||||
|
import org.geotools.styling.Mark;
|
||||||
|
import org.geotools.styling.NamedLayer;
|
||||||
|
import org.geotools.styling.RasterSymbolizerImpl;
|
||||||
|
import org.geotools.styling.Rule;
|
||||||
|
import org.geotools.styling.SLDTransformer;
|
||||||
|
import org.geotools.styling.ShadedReliefImpl;
|
||||||
|
import org.geotools.styling.Stroke;
|
||||||
|
import org.geotools.styling.Style;
|
||||||
|
import org.geotools.styling.StyleBuilder;
|
||||||
|
import org.geotools.styling.StyleFactory;
|
||||||
|
import org.geotools.styling.StyledLayer;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
import org.geotools.styling.UserLayer;
|
||||||
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class StyleMngr
|
||||||
|
{
|
||||||
|
public static final StyleFactory sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
|
||||||
|
public static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
||||||
|
public static final StyleBuilder sb = new StyleBuilder(sf, ff);
|
||||||
|
|
||||||
|
private static final Color LINE_COLOR = Color.BLUE;
|
||||||
|
private static final Color FILL_COLOR = Color.CYAN;
|
||||||
|
private static final float OPACITY = 1.0F;
|
||||||
|
private static final float LINE_WIDTH = 1.0F;
|
||||||
|
private static final float POINT_SIZE = 10.0F;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
Hints.putSystemDefault(Hints.STYLE_FACTORY, O2StyleFactory.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Style> getStylesFromSLD(StyledLayerDescriptor sld)
|
||||||
|
{
|
||||||
|
ArrayList styles = new ArrayList();
|
||||||
|
|
||||||
|
if (sld == null) {
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator sldLayerIter = sld.layers().iterator();
|
||||||
|
Iterator sldStyleIter;
|
||||||
|
for (; sldLayerIter.hasNext();
|
||||||
|
sldStyleIter.hasNext())
|
||||||
|
{
|
||||||
|
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
||||||
|
|
||||||
|
sldStyleIter = getStylesIterator(styledLayer);
|
||||||
|
Style tempStyle = (Style)sldStyleIter.next();
|
||||||
|
styles.add(tempStyle);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Style> getStylesFromSLD(String layerName, StyledLayerDescriptor sld)
|
||||||
|
{
|
||||||
|
ArrayList styles = new ArrayList();
|
||||||
|
|
||||||
|
if ((ServerUtil.isNullString(layerName)) || (sld == null)) {
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
layerName = layerName.trim().toUpperCase();
|
||||||
|
|
||||||
|
Iterator sldLayerIter = sld.layers().iterator();
|
||||||
|
while (sldLayerIter.hasNext()) {
|
||||||
|
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
||||||
|
|
||||||
|
if ((styledLayer.getName() != null) &&
|
||||||
|
(styledLayer.getName().equalsIgnoreCase(layerName)))
|
||||||
|
{
|
||||||
|
styles.addAll(getStyles(styledLayer));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Style> getStylesFromSLD(String layerName, String styleName, StyledLayerDescriptor sld)
|
||||||
|
{
|
||||||
|
ArrayList styles = new ArrayList();
|
||||||
|
|
||||||
|
if ((ServerUtil.isNullString(layerName)) || (sld == null)) {
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
layerName = layerName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (!ServerUtil.isNullString(styleName)) {
|
||||||
|
styleName = styleName.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator sldLayerIter = sld.layers().iterator();
|
||||||
|
Iterator sldStyleIter;
|
||||||
|
label188: for (; sldLayerIter.hasNext();
|
||||||
|
sldStyleIter.hasNext())
|
||||||
|
{
|
||||||
|
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
||||||
|
|
||||||
|
if ((styledLayer.getName() == null) ||
|
||||||
|
(!styledLayer.getName().equalsIgnoreCase(layerName)))
|
||||||
|
break label188;
|
||||||
|
sldStyleIter = getStylesIterator(styledLayer);
|
||||||
|
//continue; thkim
|
||||||
|
Style tempStyle = (Style)sldStyleIter.next();
|
||||||
|
|
||||||
|
if ((ServerUtil.isNullString(styleName)) &&
|
||||||
|
(ServerUtil.isNullString(tempStyle.getName())))
|
||||||
|
{
|
||||||
|
tempStyle.setName("");
|
||||||
|
styles.add(tempStyle);
|
||||||
|
}
|
||||||
|
else if (tempStyle.getName().equalsIgnoreCase(styleName))
|
||||||
|
{
|
||||||
|
styles.add(tempStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Style> getStyles(StyledLayer layer) {
|
||||||
|
if ((layer instanceof NamedLayer)) {
|
||||||
|
return ((NamedLayer)layer).styles();
|
||||||
|
}
|
||||||
|
return ((UserLayer)layer).userStyles();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Iterator<Style> getStylesIterator(StyledLayer layer)
|
||||||
|
{
|
||||||
|
if ((layer instanceof NamedLayer)) {
|
||||||
|
return ((NamedLayer)layer).styles().iterator();
|
||||||
|
}
|
||||||
|
return ((UserLayer)layer).userStyles().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void writeServiceSLD100(StyledLayerDescriptor sld)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String layerName = sld.getName();
|
||||||
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
|
||||||
|
if( false ) { // thkim
|
||||||
|
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (File file : files) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
File writeFile = new File(ServerContext.getStylesFolder(), layerName + ".sld");
|
||||||
|
|
||||||
|
SLDTransformer styleTransform = new SLDTransformer();
|
||||||
|
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||||
|
styleTransform.setIndentation(5);
|
||||||
|
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
|
"[StyleMngr.writeServiceSLD]" +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void writeServiceSLD110(StyledLayerDescriptor sld)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String layerName = sld.getName();
|
||||||
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
if( false ) { // thkim
|
||||||
|
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (File file : files) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
File writeFile = new File(ServerContext.getStylesFolder(), layerName + ".sld");
|
||||||
|
|
||||||
|
SLDTransformer110 styleTransform = new SLDTransformer110();
|
||||||
|
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||||
|
styleTransform.setIndentation(5);
|
||||||
|
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
|
"[StyleMngr.writeServiceSLD]" +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StyledLayerDescriptor readServiceSLD(String layerName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
if( false ) { // thkim
|
||||||
|
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (files.length > 0) {
|
||||||
|
return parseSLD(new FileInputStream(files[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[STYLE]",
|
||||||
|
"[StyleMngr.readServiceSLD] " + layerName + ".sld is not exist");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
|
"[StyleMngr.readServiceSLD]" +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StyledLayerDescriptor parseSLD(InputStream stream)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] sldBytes = ServerUtil.cloneInputStream(stream);
|
||||||
|
String version = getSLDVersion(new ByteArrayInputStream(sldBytes));
|
||||||
|
|
||||||
|
Object obj = null;
|
||||||
|
if (version.equals("1.1.0"))
|
||||||
|
{
|
||||||
|
SLDConfiguration110 config = new SLDConfiguration110();
|
||||||
|
Parser parser = new Parser(config);
|
||||||
|
obj = parser.parse(new ByteArrayInputStream(sldBytes));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SLDParser100 parser = new SLDParser100(sf, new ByteArrayInputStream(sldBytes));
|
||||||
|
obj = parser.parseSLD();
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)obj;
|
||||||
|
|
||||||
|
RefineStyleVisitor uVisitor = new RefineStyleVisitor();
|
||||||
|
sld.accept(uVisitor);
|
||||||
|
|
||||||
|
sld = (StyledLayerDescriptor)uVisitor.getCopy();
|
||||||
|
|
||||||
|
return sld;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.parseSLD]" + e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (stream != null)
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
stream = null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSLDVersion(InputStream stream)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
Document dDoc = builder.parse(stream);
|
||||||
|
|
||||||
|
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||||
|
String version = (String)xPath.evaluate("//StyledLayerDescriptor/@version", dDoc, XPathConstants.STRING);
|
||||||
|
|
||||||
|
return version;
|
||||||
|
} catch (ParserConfigurationException localParserConfigurationException) {
|
||||||
|
} catch (SAXException localSAXException) {
|
||||||
|
} catch (IOException localIOException1) {
|
||||||
|
} catch (XPathExpressionException localXPathExpressionException) {
|
||||||
|
} finally {
|
||||||
|
if (stream != null) {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
stream = null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "1.1.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Style getDefaultUserStyle(LayerFactory.LayerType layerType, String serverName, String tableName, String layerName)
|
||||||
|
{
|
||||||
|
Style uStyle = sf.createStyle();
|
||||||
|
uStyle.featureTypeStyles().add(getDefaultFeatureTypeStyle(layerType, serverName, tableName));
|
||||||
|
uStyle.setDefault(true);
|
||||||
|
uStyle.setName("");
|
||||||
|
|
||||||
|
if (!ServerUtil.isNullString(layerName)) {
|
||||||
|
uStyle.setName(layerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FeatureTypeStyle getDefaultFeatureTypeStyle(LayerFactory.LayerType layerType, String serverName, String tableName)
|
||||||
|
{
|
||||||
|
Rule rule = null;
|
||||||
|
if ((layerType == LayerFactory.LayerType.JDBC) ||
|
||||||
|
(layerType == LayerFactory.LayerType.GEOWAVE) ||
|
||||||
|
(layerType == LayerFactory.LayerType.SHAPE) ||
|
||||||
|
(layerType == LayerFactory.LayerType.O2WPSVEC))
|
||||||
|
{
|
||||||
|
GeometryMngr.GeomType geomType = GeometryMngr.GeomType.LINE;
|
||||||
|
String geomColumnName = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
geomType = GeometryMngr.getGeometryType(layerType, serverName, tableName);
|
||||||
|
geomColumnName = GeometryMngr.getGeometryColumn(layerType, serverName, tableName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.getDefaultFeatureTypeStyle]" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
rule = createFeatureTypeRule(geomType, geomColumnName);
|
||||||
|
}
|
||||||
|
else if ((layerType == LayerFactory.LayerType.O2DEM) ||
|
||||||
|
(layerType == LayerFactory.LayerType.O2WPSCOV))
|
||||||
|
{
|
||||||
|
RasterSymbolizerImpl sym = new RasterSymbolizerImpl();
|
||||||
|
sym.setShadedRelief(new ShadedReliefImpl());
|
||||||
|
|
||||||
|
rule = sf.createRule();
|
||||||
|
rule.setName("RULE");
|
||||||
|
rule.symbolizers().add(sym);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rule = sf.createRule();
|
||||||
|
rule.setName("RULE");
|
||||||
|
rule.symbolizers().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
FeatureTypeStyle ftStyle = sf.createFeatureTypeStyle();
|
||||||
|
ftStyle.rules().add(rule);
|
||||||
|
ftStyle.setName("FEATURETYPESTYLE");
|
||||||
|
|
||||||
|
return ftStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Rule createFeatureTypeRule(GeometryMngr.GeomType geomType, String geomColumnName) {
|
||||||
|
Symbolizer symbolizer = null;
|
||||||
|
Fill fill = null;
|
||||||
|
Stroke stroke = sf.createStroke(ff.literal(LINE_COLOR), ff.literal(1.0F));
|
||||||
|
|
||||||
|
switch (geomType) {
|
||||||
|
case POLYGON:
|
||||||
|
fill = sf.createFill(ff.literal(FILL_COLOR), ff.literal(1.0F));
|
||||||
|
symbolizer = sf.createPolygonSymbolizer(stroke, fill, geomColumnName);
|
||||||
|
symbolizer.setName("POLYGONSYMBOLIZER");
|
||||||
|
break;
|
||||||
|
case POINT:
|
||||||
|
symbolizer = sf.createLineSymbolizer(stroke, geomColumnName);
|
||||||
|
symbolizer.setName("LINESYMBOLIZER");
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
fill = sf.createFill(ff.literal(FILL_COLOR), ff.literal(1.0F));
|
||||||
|
|
||||||
|
Mark mark = sf.getCircleMark();
|
||||||
|
mark.setFill(fill);
|
||||||
|
mark.setStroke(stroke);
|
||||||
|
|
||||||
|
Graphic graphic = sf.createDefaultGraphic();
|
||||||
|
graphic.graphicalSymbols().clear();
|
||||||
|
graphic.graphicalSymbols().add(mark);
|
||||||
|
graphic.setSize(ff.literal(10.0F));
|
||||||
|
|
||||||
|
symbolizer = sf.createPointSymbolizer(graphic, geomColumnName);
|
||||||
|
symbolizer.setName("POINTSYMBOLIZER");
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule rule = sf.createRule();
|
||||||
|
rule.setName("RULE");
|
||||||
|
rule.symbolizers().add(symbolizer);
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MarkStyle2D createDefaultMarkStyle()
|
||||||
|
{
|
||||||
|
MarkStyle2D mark = new MarkStyle2D();
|
||||||
|
mark.setShape(new Rectangle2D.Double(-0.5D, -0.5D, 1.0D, 1.0D));
|
||||||
|
|
||||||
|
mark.setFill(FILL_COLOR);
|
||||||
|
mark.setFillComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||||
|
|
||||||
|
mark.setStroke(new BasicStroke(1.0F, 2, 0, 1.0F));
|
||||||
|
|
||||||
|
mark.setContour(LINE_COLOR);
|
||||||
|
mark.setContourComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||||
|
|
||||||
|
mark.setSize(16.0D);
|
||||||
|
|
||||||
|
return mark;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import org.geotools.sld.v1_1.bindings.StyledLayerDescriptorBinding;
|
||||||
|
import org.geotools.styling.NamedLayer;
|
||||||
|
import org.geotools.styling.StyleFactory;
|
||||||
|
import org.geotools.styling.StyledLayer;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.styling.UserLayer;
|
||||||
|
import org.geotools.xml.ElementInstance;
|
||||||
|
import org.geotools.xml.Node;
|
||||||
|
|
||||||
|
public class StyledLayerDescriptorBinding110 extends StyledLayerDescriptorBinding
|
||||||
|
{
|
||||||
|
public StyledLayerDescriptorBinding110(StyleFactory styleFactory)
|
||||||
|
{
|
||||||
|
super(styleFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object parse(ElementInstance instance, Node node, Object value)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)super.parse(instance, node, value);
|
||||||
|
|
||||||
|
ArrayList layers = new ArrayList();
|
||||||
|
|
||||||
|
List list = node.getChildren();
|
||||||
|
Iterator iter = list.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Node child = (Node)iter.next();
|
||||||
|
|
||||||
|
if ((child.getValue() instanceof NamedLayer))
|
||||||
|
layers.add((NamedLayer)child.getValue());
|
||||||
|
else if ((child.getValue() instanceof UserLayer)) {
|
||||||
|
layers.add((UserLayer)child.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sld.setStyledLayers((StyledLayer[])layers.toArray(new StyledLayer[layers.size()]));
|
||||||
|
|
||||||
|
return sld;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.algorithm.MinimumDiameter;
|
||||||
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
|
||||||
|
import org.geotools.renderer.style.TextStyle2D;
|
||||||
|
import org.geotools.styling.TextSymbolizer.PolygonAlignOptions;
|
||||||
|
|
||||||
|
class TextStyle2DEx extends TextStyle2D
|
||||||
|
{
|
||||||
|
Double alternateRotation;
|
||||||
|
LabelCacheItemEx item;
|
||||||
|
|
||||||
|
public TextStyle2DEx(LabelCacheItemEx item)
|
||||||
|
{
|
||||||
|
super(item.getTextStyle());
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupPolygonAlign(PreparedGeometry pg) {
|
||||||
|
if (this.item.getPolygonAlign() == org.geotools.styling.TextSymbolizer.PolygonAlignOptions.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean flipRotation(Geometry geometry)
|
||||||
|
{
|
||||||
|
if (this.item.getPolygonAlign() == org.geotools.styling.TextSymbolizer.PolygonAlignOptions.NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.alternateRotation == null) {
|
||||||
|
double radians = 0.0D;
|
||||||
|
if (this.item.getPolygonAlign() == org.geotools.styling.TextSymbolizer.PolygonAlignOptions.ORTHO)
|
||||||
|
radians = calcPolygonAlignOrthoAngle(geometry);
|
||||||
|
else if (this.item.getPolygonAlign() == org.geotools.styling.TextSymbolizer.PolygonAlignOptions.MBR) {
|
||||||
|
radians = calcPolygonAlignMBRAngle(geometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.alternateRotation = Double.valueOf(radians);
|
||||||
|
}
|
||||||
|
|
||||||
|
double temp = getRotation();
|
||||||
|
setRotation(this.alternateRotation.doubleValue());
|
||||||
|
this.alternateRotation = Double.valueOf(temp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double calcPolygonAlignOrthoAngle(Geometry geometry) {
|
||||||
|
Envelope envelope = geometry.getEnvelopeInternal();
|
||||||
|
if (envelope.getHeight() > envelope.getWidth()) {
|
||||||
|
return -1.570796326794897D;
|
||||||
|
}
|
||||||
|
return 0.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
double calcPolygonAlignMBRAngle(Geometry geometry)
|
||||||
|
{
|
||||||
|
Geometry mbr = new com.vividsolutions.jts.algorithm.MinimumDiameter(geometry).getMinimumRectangle();
|
||||||
|
|
||||||
|
Coordinate[] coordinates = mbr.getCoordinates();
|
||||||
|
double dy;
|
||||||
|
double dx;
|
||||||
|
if (coordinates[0].distance(coordinates[1]) > coordinates[1].distance(coordinates[2])) {
|
||||||
|
dx = coordinates[1].x - coordinates[0].x;
|
||||||
|
dy = coordinates[1].y - coordinates[0].y;
|
||||||
|
} else {
|
||||||
|
dx = coordinates[2].x - coordinates[1].x;
|
||||||
|
dy = coordinates[2].y - coordinates[1].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
double angle = Math.atan(dy / dx);
|
||||||
|
|
||||||
|
if (Math.abs(angle - 1.570796326794897D) < 0.0174532925199433D) {
|
||||||
|
angle = -1.570796326794897D + Math.abs(angle - 1.570796326794897D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.Rectangle2D.Double;
|
||||||
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
class TransformedIconEx
|
||||||
|
implements Icon
|
||||||
|
{
|
||||||
|
AffineTransform at;
|
||||||
|
Icon icon;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
public TransformedIconEx(Icon icon, AffineTransform at)
|
||||||
|
{
|
||||||
|
this.icon = icon;
|
||||||
|
this.at = at;
|
||||||
|
Rectangle2D bounds = new Rectangle2D.Double(0.0D, 0.0D, icon.getIconWidth(), icon.getIconHeight());
|
||||||
|
bounds = at.createTransformedShape(bounds).getBounds2D();
|
||||||
|
this.width = ((int)Math.round(bounds.getWidth()));
|
||||||
|
this.height = ((int)Math.round(bounds.getHeight()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIconHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIconWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
AffineTransform tmp = g2d.getTransform();
|
||||||
|
Object oldInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
|
||||||
|
if (oldInterpolation == null)
|
||||||
|
oldInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AffineTransform at = new AffineTransform(tmp);
|
||||||
|
at.concatenate(this.at);
|
||||||
|
g2d.setTransform(at);
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||||
|
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
this.icon.paintIcon(c, g2d, 0, 0);
|
||||||
|
} finally {
|
||||||
|
g2d.setTransform(tmp);
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
public class WMSGetMap
|
||||||
|
{
|
||||||
|
GetMapRequest requestObj = null;
|
||||||
|
|
||||||
|
public WMSGetMap(GetMapRequest requestObj)
|
||||||
|
{
|
||||||
|
this.requestObj = requestObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document getMap(HttpServletResponse resp)
|
||||||
|
{
|
||||||
|
AVList params = new AVList();
|
||||||
|
|
||||||
|
params.setValue("request.wms.layers", this.requestObj.getLayers());
|
||||||
|
params.setValue("request.wms.bbox", this.requestObj.getBbox());
|
||||||
|
params.setValue("request.wms.width", Integer.valueOf(this.requestObj.getWidth()));
|
||||||
|
params.setValue("request.wms.height", Integer.valueOf(this.requestObj.getHeight()));
|
||||||
|
params.setValue("request.wms.format", this.requestObj.getFormat());
|
||||||
|
params.setValue("request.wms.transparent", Boolean.valueOf(this.requestObj.isTransparent()));
|
||||||
|
params.setValue("request.wms.bgcolor", this.requestObj.getBgcolor());
|
||||||
|
params.setValue("request.wms.styles", this.requestObj.getStyles());
|
||||||
|
params.setValue("request.wms.filter", this.requestObj.getFilter());
|
||||||
|
|
||||||
|
if (this.requestObj.getSld() != null) {
|
||||||
|
params.setValue("request.wms.sld", this.requestObj.getSld());
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage image = null;
|
||||||
|
Document doc = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
image = RenderMngr.productMap(params);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException("WMS GetMap Exception : Image process fails : " + e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Image process fails : " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writeImage(image, resp);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException("WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeImage(BufferedImage image, HttpServletResponse resp)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
OutputStream out = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String format = this.requestObj.getFormat();
|
||||||
|
String[] formatElement = format.split("/");
|
||||||
|
|
||||||
|
resp.setContentType(format);
|
||||||
|
out = resp.getOutputStream();
|
||||||
|
|
||||||
|
if (format.toUpperCase().contains("PNG"))
|
||||||
|
O2PngWriter.writePNG(image, out);
|
||||||
|
else {
|
||||||
|
ImageIO.write(image, formatElement[1], out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.jdom.Document;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.input.SAXBuilder;
|
||||||
|
|
||||||
|
public class WMSLayer extends LinkLayer
|
||||||
|
{
|
||||||
|
private Envelope bbox;
|
||||||
|
|
||||||
|
public WMSLayer(AVList params)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super(params);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HashMap serviceLayers = getServiceLayers();
|
||||||
|
|
||||||
|
Envelope layerBBox = null;
|
||||||
|
|
||||||
|
String[] layerNames = getServiceLayerNames().split(",");
|
||||||
|
for (String name : layerNames) {
|
||||||
|
Envelope envelope = (Envelope)serviceLayers.get(name.trim());
|
||||||
|
if (envelope == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
if (layerBBox == null)
|
||||||
|
layerBBox = envelope;
|
||||||
|
else {
|
||||||
|
layerBBox.expandToInclude(envelope);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bbox = layerBBox;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, Envelope> getServiceLayers()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HashMap serviceLayers = new HashMap();
|
||||||
|
|
||||||
|
URL url = new URL(getServiceURL().toURI() + "?request=getlayerinfo");
|
||||||
|
URLConnection conn = url.openConnection();
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(1000);
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.connect();
|
||||||
|
|
||||||
|
SAXBuilder builder = new SAXBuilder();
|
||||||
|
Document document = builder.build(conn.getInputStream());
|
||||||
|
Element rootNode = document.getRootElement();
|
||||||
|
|
||||||
|
List list = rootNode.getChildren("layer");
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++)
|
||||||
|
{
|
||||||
|
Element layer = (Element)list.get(i);
|
||||||
|
|
||||||
|
String name = layer.getChild("layer_name").getTextTrim();
|
||||||
|
Boolean type = Boolean.valueOf(layer.getChild("layer_type").getTextTrim().toLowerCase().equals("o2map_image"));
|
||||||
|
|
||||||
|
if (type.booleanValue())
|
||||||
|
{
|
||||||
|
Element bbox = layer.getChild("service_info").getChild("envelope");
|
||||||
|
|
||||||
|
Double minx = Double.valueOf(Double.parseDouble(bbox.getChild("minx").getTextTrim()));
|
||||||
|
Double miny = Double.valueOf(Double.parseDouble(bbox.getChild("miny").getTextTrim()));
|
||||||
|
Double maxx = Double.valueOf(Double.parseDouble(bbox.getChild("maxx").getTextTrim()));
|
||||||
|
Double maxy = Double.valueOf(Double.parseDouble(bbox.getChild("maxy").getTextTrim()));
|
||||||
|
|
||||||
|
Envelope envelope = new Envelope(minx.doubleValue(), maxx.doubleValue(), miny.doubleValue(), maxy.doubleValue());
|
||||||
|
|
||||||
|
serviceLayers.put(name, envelope);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceLayers;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBBox()
|
||||||
|
{
|
||||||
|
return new ReferencedEnvelope(this.bbox, getCRS());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,704 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.data.DataAccessFactory.Param;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
|
import org.geotools.data.shapefile.ShpDataStore;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
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.JDBCDataStore;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.Feature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.opengis.filter.Id;
|
||||||
|
import org.opengis.filter.identity.GmlObjectId;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class WpsVecStoreMngr {
|
||||||
|
private static ConcurrentHashMap<String, ContentDataStore> dataStores = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
private static JDBCDataStore datastore = null;
|
||||||
|
public static final int DEFAULT_MIN_CONN = 10;
|
||||||
|
public static final int DEFAULT_MAX_CONN = 50;
|
||||||
|
public static final int DEFAULT_FETCH_SIZE = 1000;
|
||||||
|
public static final int DEFAULT_CONN_TIMEOUT = 30;
|
||||||
|
public static final int DEFAULT_PS_CACHE_SIZE = 100;
|
||||||
|
public static final String DEFAULT_PK_COLUMN = "LAYER_NAME";
|
||||||
|
|
||||||
|
public static synchronized void initLayers()
|
||||||
|
{
|
||||||
|
initDataStore();
|
||||||
|
|
||||||
|
dataStores = new ConcurrentHashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JDBCDataStore getDataStore() throws Exception
|
||||||
|
{
|
||||||
|
if (datastore == null) {
|
||||||
|
throw new IllegalArgumentException("o2wps_datastore is NULL.");
|
||||||
|
}
|
||||||
|
return datastore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disposeDataStore()
|
||||||
|
{
|
||||||
|
if (datastore != null) {
|
||||||
|
datastore.dispose();
|
||||||
|
datastore = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initDataStore()
|
||||||
|
{
|
||||||
|
disposeDataStore();
|
||||||
|
|
||||||
|
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||||
|
|
||||||
|
String sName = "O2WPS_MASTER";
|
||||||
|
String sType = (String)map.get("conf.xml.map.dbtype");
|
||||||
|
sType = sType.trim();
|
||||||
|
String sIP = (String)map.get("conf.xml.map.host");
|
||||||
|
sIP = sIP.trim();
|
||||||
|
String sPort = (String)map.get("conf.xml.map.port");
|
||||||
|
sPort = sPort.trim();
|
||||||
|
String database = (String)map.get("conf.xml.map.database");
|
||||||
|
database = database.trim();
|
||||||
|
String dbUser = (String)map.get("conf.xml.map.user");
|
||||||
|
dbUser = dbUser.trim();
|
||||||
|
String dbPass = (String)map.get("conf.xml.map.passwd");
|
||||||
|
dbPass = dbPass.trim();
|
||||||
|
|
||||||
|
HashMap params = new HashMap();
|
||||||
|
|
||||||
|
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, Integer.valueOf(10));
|
||||||
|
params.put(O2DSFactory.MAXCONN.key, Integer.valueOf(50));
|
||||||
|
params.put(O2DSFactory.MAXWAIT.key, Integer.valueOf(30));
|
||||||
|
params.put(O2DSFactory.VALIDATECONN.key, Boolean.FALSE);
|
||||||
|
|
||||||
|
params.put(O2DSFactory.FETCHSIZE.key, Integer.valueOf(1000));
|
||||||
|
params.put(O2DSFactory.MAX_OPEN_PREPARED_STATEMENTS.key, Integer.valueOf(100));
|
||||||
|
|
||||||
|
params.put(O2DSFactory.EXPOSE_PK.key, Boolean.TRUE);
|
||||||
|
|
||||||
|
params.put(O2DSFactory.O2_SERVER_NAME.key, sName);
|
||||||
|
params.put(O2DSFactory.O2_PK_COLUMN_NAME.key, "LAYER_NAME");
|
||||||
|
params.put(O2DSFactory.O2_USE_SPATIAL.key, Boolean.valueOf(false));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Crate Jdbc DataStore for o2wps :: " + params);
|
||||||
|
|
||||||
|
datastore = new O2DSFactory(params).getDataStore();
|
||||||
|
datastore.getTypeNames();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Success to add Jdbc DataStore for o2wps");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Fail to add Jdbc DataStore for o2wps :: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!isExistTable(O2WpsMetaTableType.LAYERINFO_TBL.toString())) {
|
||||||
|
createTable(sType, O2WpsMetaTableType.LAYERINFO_TBL.toString(), buildFieldInfo(O2WpsMetaTableType.LAYERINFO_TBL.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isExistTable(O2WpsMetaTableType.STORELYRINFO_TBL.toString()))
|
||||||
|
{
|
||||||
|
createTable(sType, O2WpsMetaTableType.STORELYRINFO_TBL.toString(), buildFieldInfo(O2WpsMetaTableType.STORELYRINFO_TBL.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isExistTable(O2WpsMetaTableType.SHARELYRINFO_TBL.toString()))
|
||||||
|
{
|
||||||
|
createTable(sType, O2WpsMetaTableType.SHARELYRINFO_TBL.toString(), buildFieldInfo(O2WpsMetaTableType.SHARELYRINFO_TBL.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FeatureLayer addLayer(File layerFile, String layerName, String layerType, CoordinateReferenceSystem crs, String hashTag, String desc, String authorId, O2WpsMetaTableType metaTblType)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (!layerFile.exists()) {
|
||||||
|
throw new IOException("O2WPSVECLayer data file is not exist [" + layerFile.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
String dataFileName = ServerUtil.getFileName(layerFile);
|
||||||
|
if (ServerUtil.isNullString(dataFileName)) {
|
||||||
|
throw new IOException("O2WPSVECLayer FileName is not valid [" + dataFileName + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataFileName = dataFileName.trim().toUpperCase();
|
||||||
|
String dataFileExt = ServerUtil.getFileExtension(layerFile);
|
||||||
|
if (ServerUtil.isNullString(dataFileExt)) {
|
||||||
|
throw new IOException("O2WPSVECLayer FileExtension is not valid [" + dataFileExt + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dataFileExt.equalsIgnoreCase("SHP"))
|
||||||
|
{
|
||||||
|
createShpDataStore(dataFileName, layerName, layerFile, crs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IOException("Not supported FileExtension [" + dataFileExt + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", ServerContext.getMap().getName());
|
||||||
|
params.setValue("conf.service.layer.name", layerName);
|
||||||
|
|
||||||
|
if (layerType.toUpperCase().equalsIgnoreCase("FEA"))
|
||||||
|
params.setValue("conf.service.ref.server", LayerFactory.LayerType.O2WPSVEC.getType());
|
||||||
|
else {
|
||||||
|
params.setValue("conf.service.ref.server", LayerFactory.LayerType.O2WPSCOV.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
params.setValue("conf.service.ref.source", dataFileName);
|
||||||
|
params.setValue("conf.service.o2wps.source.path", layerFile.toString());
|
||||||
|
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.o2wps.hashtag", hashTag);
|
||||||
|
params.setValue("conf.service.description", desc);
|
||||||
|
|
||||||
|
if (authorId == null)
|
||||||
|
params.setValue("conf.service.o2wps.author.id", "Anonymous");
|
||||||
|
else {
|
||||||
|
params.setValue("conf.service.o2wps.author.id", authorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer layer = null;
|
||||||
|
if (layerType.toUpperCase().equalsIgnoreCase("FEA"))
|
||||||
|
layer = LayerFactory.createLayer(LayerFactory.LayerType.O2WPSVEC, params);
|
||||||
|
else {
|
||||||
|
layer = LayerFactory.createLayer(LayerFactory.LayerType.O2WPSCOV, params);
|
||||||
|
}
|
||||||
|
ServerContext.getMap().getO2WpsLayerSet().addLayer(metaTblType.getName(), layer);
|
||||||
|
|
||||||
|
return (FeatureLayer)layer;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ShpDataStore createShpDataStore(String dataFileName, String name, File file, CoordinateReferenceSystem crs)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ShpDataStore store = new ShpDataStore(name, file);
|
||||||
|
store.setCharset(Charset.forName("EUC-KR"));
|
||||||
|
store.setBufferCachingEnabled(true);
|
||||||
|
store.setMemoryMapped(false);
|
||||||
|
store.setIndexed(true);
|
||||||
|
store.setIndexCreationEnabled(false);
|
||||||
|
|
||||||
|
store.forceSchemaCRS(crs);
|
||||||
|
|
||||||
|
store.setNamespaceURI(ServerContext.getMap().getNameSpaceURI());
|
||||||
|
ContentDataStoreRefinder.refindShapefileDataStore(store);
|
||||||
|
|
||||||
|
if (ShpIndexMngr.isNeedToMakeIndex(file)) {
|
||||||
|
ShpIndexMngr.createIndex(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataStores.put(dataFileName, store);
|
||||||
|
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HashMap<String, Object> getShpStoreInfoByDB(Statement st, String metaTableName, String storeName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
storeName = storeName.trim().toUpperCase();
|
||||||
|
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT * FROM ");
|
||||||
|
sql.append(metaTableName);
|
||||||
|
sql.append(" WHERE ");
|
||||||
|
sql.append(O2WpsMetaFieldName.LAYERINFO_FLD_LAYERSRC.toString()).append("=");
|
||||||
|
sql.append("'");
|
||||||
|
sql.append(storeName).append("'");
|
||||||
|
|
||||||
|
rs = st.executeQuery(sql.toString());
|
||||||
|
boolean bFind = rs.next();
|
||||||
|
if (bFind) {
|
||||||
|
String fileName = rs.getString(O2WpsMetaFieldName.LAYERINFO_FLD_SRCPATH.toString());
|
||||||
|
String crsCode = rs.getString(O2WpsMetaFieldName.LAYERINFO_FLD_REFSRID.toString());
|
||||||
|
String layerName = rs.getString(O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString());
|
||||||
|
HashMap ret = new HashMap();
|
||||||
|
ret.put("filename", fileName);
|
||||||
|
ret.put("crs", crsCode);
|
||||||
|
ret.put("layername", layerName);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (rs != null)
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
disposeDataStores();
|
||||||
|
initLayers();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logInfo("[O2WPS]", "Success to reload O2WpsStore.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]", "Fail to reload O2WpsStore. Now use previous O2WpsStore :: " + e);
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContentDataStore getShpDataStore(String storeName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (ServerUtil.isNullString(storeName)) {
|
||||||
|
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentDataStore store = null;
|
||||||
|
|
||||||
|
if (!dataStores.isEmpty()) {
|
||||||
|
store = (ContentDataStore)dataStores.get(storeName.trim().toUpperCase());
|
||||||
|
|
||||||
|
if (store != null) {
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap infoMap = null;
|
||||||
|
|
||||||
|
JDBCDataStore ds = getDataStore();
|
||||||
|
Connection cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||||
|
Statement st = cx.createStatement();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
infoMap = getShpStoreInfoByDB(st, O2WpsMetaTableType.LAYERINFO_TBL.toString(), storeName);
|
||||||
|
if (infoMap == null) {
|
||||||
|
infoMap = getShpStoreInfoByDB(st, O2WpsMetaTableType.STORELYRINFO_TBL.toString(), storeName);
|
||||||
|
if (infoMap == null) {
|
||||||
|
infoMap = getShpStoreInfoByDB(st, O2WpsMetaTableType.SHARELYRINFO_TBL.toString(), storeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (infoMap == null) return null;
|
||||||
|
String fileName = (String)infoMap.get("filename");
|
||||||
|
String crsCode = (String)infoMap.get("crs");
|
||||||
|
String layerName = (String)infoMap.get("layername");
|
||||||
|
|
||||||
|
File file = new File(fileName);
|
||||||
|
CoordinateReferenceSystem crs = CRS.decode(crsCode);
|
||||||
|
store = createShpDataStore(storeName, layerName, file, crs);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
cx.close();
|
||||||
|
st.close();
|
||||||
|
}
|
||||||
|
cx.close();
|
||||||
|
st.close();
|
||||||
|
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void disposeDataStores()
|
||||||
|
{
|
||||||
|
disposeDataStore();
|
||||||
|
|
||||||
|
if (dataStores.isEmpty()) return;
|
||||||
|
|
||||||
|
synchronized (dataStores)
|
||||||
|
{
|
||||||
|
for (String storeName : dataStores.keySet()) {
|
||||||
|
ContentDataStore store = (ContentDataStore)dataStores.get(storeName);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerContext.getMap().getO2WpsLayerSet().removeLayer(LayerFactory.LayerType.O2WPSVEC, LayerFactory.LayerType.O2WPSVEC.getType(), storeName);
|
||||||
|
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]",
|
||||||
|
"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("[O2WPS]", "Parameter StoreName is NULL");
|
||||||
|
return false;
|
||||||
|
}if (dataStores.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]", "DataStore is NULL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
storeName = storeName.trim().toUpperCase();
|
||||||
|
|
||||||
|
synchronized (dataStores)
|
||||||
|
{
|
||||||
|
ContentDataStore store = (ContentDataStore)dataStores.get(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]", "DataStore [" + storeName + "] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerContext.getMap().getO2WpsLayerSet().removeLayer(LayerFactory.LayerType.O2WPSVEC, LayerFactory.LayerType.O2WPSVEC.getType(), storeName);
|
||||||
|
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]",
|
||||||
|
"Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean deleteShpDataStore(String storeName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ContentDataStore store = getShpDataStore(storeName.trim().toUpperCase());
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]", "DataStore [" + storeName + "] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((store instanceof ShpDataStore)) {
|
||||||
|
File shpFile = ((ShpDataStore)store).getShpFile();
|
||||||
|
|
||||||
|
disposeDataStore(storeName);
|
||||||
|
deleteShpFiles(shpFile);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]",
|
||||||
|
"Fail to delete ShpDataStore [" + storeName + "] :: DeleteDataStore supported SHP file only");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[O2WPS]",
|
||||||
|
"Fail to delete ShpDataStore [" + storeName + "] :: " + e);
|
||||||
|
}return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteShpFiles(File shpFile)
|
||||||
|
{
|
||||||
|
String fileName = ServerUtil.getFileName(shpFile).toUpperCase();
|
||||||
|
|
||||||
|
File rootFile = shpFile.getParentFile();
|
||||||
|
FilenameFilter nameFilter = new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
return name.toUpperCase().startsWith(WpsVecStoreMngr.this + ".");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (File file : rootFile.listFiles(nameFilter)) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteEmptyDir(rootFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteEmptyDir(File dir) {
|
||||||
|
if (dir.list().length == 0) {
|
||||||
|
dir.delete();
|
||||||
|
deleteEmptyDir(dir.getParentFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getGmlObject(GmlObjectId id, Hints hints)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String[] fids = id.getID().split("\\.");
|
||||||
|
if (fids.length != 2) {
|
||||||
|
LogMngr.getInstance().logDebug("[O2WPS]",
|
||||||
|
"Unable to determine store type for GmlObjectId :" + id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String storeName = fids[0].trim().toUpperCase();
|
||||||
|
ContentDataStore store = getShpDataStore(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logDebug("[O2WPS]",
|
||||||
|
"DataStore is not exist for GmlObjectId ::" + storeName);
|
||||||
|
throw new IllegalArgumentException("DataStore is not exist for GmlObjectId ::" + storeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleFeatureType featureType = store.getSchema(storeName);
|
||||||
|
if (featureType == null) {
|
||||||
|
LogMngr.getInstance().logDebug("[O2WPS]",
|
||||||
|
"No such O2WPS type ::" + storeName);
|
||||||
|
throw new IllegalArgumentException("No such O2WPS type ::" + storeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||||
|
Query query = new Query();
|
||||||
|
query.setFilter(filter);
|
||||||
|
query.setHints(hints);
|
||||||
|
|
||||||
|
SimpleFeatureCollection features = store.getFeatureSource(storeName).getFeatures(query);
|
||||||
|
if (!features.isEmpty()) {
|
||||||
|
SimpleFeatureIterator fi = features.features();
|
||||||
|
try {
|
||||||
|
if (fi.hasNext()) {
|
||||||
|
Feature localFeature = fi.next(); return localFeature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fi.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isExistTable(String tableName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
JDBCDataStore ds = getDataStore();
|
||||||
|
Connection cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||||
|
DatabaseMetaData md = cx.getMetaData();
|
||||||
|
ResultSet rs = null;
|
||||||
|
boolean result = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rs = md.getTables(null, null, tableName, null);
|
||||||
|
if (rs.next())
|
||||||
|
result = true;
|
||||||
|
else
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
result = false;
|
||||||
|
} finally {
|
||||||
|
if (rs != null) rs.close();
|
||||||
|
if (cx != null) cx.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createTable(String dbType, String tableName, ArrayList<FieldInfo> fieldInfoList)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ((fieldInfoList == null) || (fieldInfoList.size() == 0)) {
|
||||||
|
throw new IllegalArgumentException("createtabel:fieldInfoList is NULL.");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString(dbType)) {
|
||||||
|
throw new IllegalArgumentException("createtabel:dbType is NULL.");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString(tableName)) {
|
||||||
|
throw new IllegalArgumentException("createtabel:tableName is NULL.");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("CREATE TABLE ");
|
||||||
|
sql.append(tableName).append("(");
|
||||||
|
|
||||||
|
FieldSQL fldConv = ConnMngr.getInstance().getConnObj(dbType).getFieldSQL();
|
||||||
|
for (int i = 0; i < fieldInfoList.size(); i++) {
|
||||||
|
FieldInfo fld = (FieldInfo)fieldInfoList.get(i);
|
||||||
|
String fldType = fldConv.getFieldType(fld.getType(), fld.getPrecision().intValue(), fld.getScale().intValue());
|
||||||
|
|
||||||
|
sql.append(fld.getName()).append(" ");
|
||||||
|
sql.append(fldType).append(" ");
|
||||||
|
if (fld.isNotNull()) {
|
||||||
|
sql.append("NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < fieldInfoList.size() - 1)
|
||||||
|
sql.append(", ");
|
||||||
|
else {
|
||||||
|
sql.append(" )");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
JDBCDataStore ds = getDataStore();
|
||||||
|
Connection cx = null;
|
||||||
|
Statement st = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cx = ds.getConnection(Transaction.AUTO_COMMIT);
|
||||||
|
st = cx.createStatement();
|
||||||
|
|
||||||
|
st.execute(sql.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (st != null) st.close();
|
||||||
|
if (cx != null) cx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<FieldInfo> buildFieldInfo(String tableName)
|
||||||
|
{
|
||||||
|
if ((tableName.equalsIgnoreCase(O2WpsMetaTableType.LAYERINFO_TBL.toString())) ||
|
||||||
|
(tableName.equalsIgnoreCase(O2WpsMetaTableType.STORELYRINFO_TBL.toString())) ||
|
||||||
|
(tableName.equalsIgnoreCase(O2WpsMetaTableType.SHARELYRINFO_TBL.toString())))
|
||||||
|
{
|
||||||
|
ArrayList fieldList = new ArrayList();
|
||||||
|
FieldInfo fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_LAYERNAME.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(100), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_LAYERTYPE.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(3), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_LAYERSRC.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(100), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_SRCPATH.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(255), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_SRCTYPE.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(3), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_REFSRID.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(20), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_AUTHORID.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(50), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_REGDATE.toString(),
|
||||||
|
FieldSQL.FieldType.DATE, Integer.valueOf(0), Integer.valueOf(0), false, true);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_HASHTAG.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(255), Integer.valueOf(0), false, false);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
fld = null;
|
||||||
|
fld = new FieldInfo(O2WpsMetaFieldName.LAYERINFO_FLD_DESC.toString(),
|
||||||
|
FieldSQL.FieldType.CHARACTER, Integer.valueOf(255), Integer.valueOf(0), false, false);
|
||||||
|
fieldList.add(fld);
|
||||||
|
|
||||||
|
return fieldList;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum O2WpsMetaFieldName
|
||||||
|
{
|
||||||
|
LAYERINFO_FLD_LAYERNAME("LAYER_NAME"),
|
||||||
|
LAYERINFO_FLD_LAYERTYPE("LAYER_TYPE"),
|
||||||
|
LAYERINFO_FLD_LAYERSRC("LAYER_SOURCE"),
|
||||||
|
LAYERINFO_FLD_SRCPATH("SOURCE_PATH"),
|
||||||
|
LAYERINFO_FLD_SRCTYPE("SOURCE_TYPE"),
|
||||||
|
LAYERINFO_FLD_REFSRID("REF_SRID"),
|
||||||
|
LAYERINFO_FLD_AUTHORID("AUTHOR_ID"),
|
||||||
|
LAYERINFO_FLD_REGDATE("REG_DATE"),
|
||||||
|
LAYERINFO_FLD_HASHTAG("HASH_TAG"),
|
||||||
|
LAYERINFO_FLD_DESC("DESCRIPTION");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private O2WpsMetaFieldName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum O2WpsMetaTableType
|
||||||
|
{
|
||||||
|
LAYERINFO_TBL("O2WPS_LYR_INFO"),
|
||||||
|
STORELYRINFO_TBL("O2WPS_STORE_LYR_INFO"),
|
||||||
|
SHARELYRINFO_TBL("O2WPS_SHARE_LYR_INFO");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private O2WpsMetaTableType(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.geotools.xml.InstanceComponent;
|
||||||
|
import org.geotools.xs.bindings.XSBooleanBinding;
|
||||||
|
|
||||||
|
public class XSBooleanBinding110 extends XSBooleanBinding
|
||||||
|
{
|
||||||
|
public Object parse(InstanceComponent instance, Object value)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String bStr = value.toString();
|
||||||
|
|
||||||
|
if (("1".equalsIgnoreCase(bStr)) || ("TRUE".equalsIgnoreCase(bStr)) || ("Y".equalsIgnoreCase(bStr))) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue