Commit c664829f authored by peter's avatar peter
Browse files

Initial commit in the branch

parent 8d462ca4
...@@ -24,8 +24,9 @@ public class Coordinate implements Cloneable{ ...@@ -24,8 +24,9 @@ public class Coordinate implements Cloneable{
public int y; public int y;
public final int r; public final int r;
public final int c; public final int c;
public final String direction;
public Coordinate(double lon, double lat, int r, int c, double value){ public Coordinate(double lon, double lat, int r, int c, double value, String direction){
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.value = value; this.value = value;
...@@ -33,12 +34,13 @@ public class Coordinate implements Cloneable{ ...@@ -33,12 +34,13 @@ public class Coordinate implements Cloneable{
this.y = (int)Math.round(lon); this.y = (int)Math.round(lon);
this.r=r; this.r=r;
this.c=c; this.c=c;
this.direction = direction;
} }
@Override @Override
public Coordinate clone(){ public Coordinate clone(){
return new Coordinate(lon, lat, r, c, value); return new Coordinate(lon, lat, r, c, value, null);
} }
public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){ public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){
......
...@@ -62,10 +62,10 @@ public class IsoSpline { ...@@ -62,10 +62,10 @@ public class IsoSpline {
start = iscs.getIsoSplineContainer(r, c); start = iscs.getIsoSplineContainer(r, c);
Polygon polygon = new Polygon(); Polygon polygon = new Polygon();
polygon.color=color; polygon.color=color;
if(start.hasNotUsedIsoSplineElement()){ if(start.hasIsoSplineElement()){
ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, start.ref); ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, start.ref);
int sortIndex=0; int sortIndex=0;
ises.add(start.getIsoSplineElement(true, sortIndex)); ises.add(start.getIsoSplineElement(sortIndex));
//System.out.println("new polygon " + isoLevel); //System.out.println("new polygon " + isoLevel);
direction = start.getPrimaryDirection(); direction = start.getPrimaryDirection();
current=start; current=start;
...@@ -154,7 +154,7 @@ public class IsoSpline { ...@@ -154,7 +154,7 @@ public class IsoSpline {
next = current.getNext(); next = current.getNext();
//System.out.println("rc: " + searchdirection + " (" + next.ref.r + ", "+ next.ref.c + ") direction " + current.nextDirection + " (next direction " + next.nextDirection + ")"); //System.out.println("rc: " + searchdirection + " (" + next.ref.r + ", "+ next.ref.c + ") direction " + current.nextDirection + " (next direction " + next.nextDirection + ")");
polygon.add(next.getIsoSplineElement(true, sortIndex)); polygon.add(next.getIsoSplineElement(sortIndex));
oppositeDirection = current.getOppositeDirection(current.nextDirection); oppositeDirection = current.getOppositeDirection(current.nextDirection);
next.setNextDirection(oppositeDirection); next.setNextDirection(oppositeDirection);
return next; return next;
......
...@@ -19,8 +19,7 @@ public class IsoSplineContainer { ...@@ -19,8 +19,7 @@ public class IsoSplineContainer {
public static String NO_DIRECTION = "No direction"; public static String NO_DIRECTION = "No direction";
private final IsoSplineContainers iscs; private final IsoSplineContainers iscs;
public final ArrayList<Coordinate> coords = new ArrayList(); public final ArrayList<Coordinate> coords = new ArrayList();
public boolean used = false; private IsoSplineElements ises;
private IsoSplineElement ise = null;
public final Coordinate ref; public final Coordinate ref;
private final ArrayList<String> directions = new ArrayList(); private final ArrayList<String> directions = new ArrayList();
private final ArrayList<String> compass = new ArrayList(); private final ArrayList<String> compass = new ArrayList();
...@@ -78,22 +77,22 @@ public class IsoSplineContainer { ...@@ -78,22 +77,22 @@ public class IsoSplineContainer {
public boolean hasNotUsedNeighbourInDirection(){ public boolean hasNotUsedNeighbourInDirection(){
if(ref.r>0 && nextDirection.equals(SOUTH)) if(ref.r>0 && nextDirection.equals(SOUTH))
if(getNext()!=null) if(getNext()!=null)
return getNext().hasNotUsedIsoSplineElement(); return getNext().hasIsoSplineElement();
else else
return false; return false;
if(ref.c>0 && nextDirection.equals(WEST)) if(ref.c>0 && nextDirection.equals(WEST))
if(getNext()!=null) if(getNext()!=null)
return getNext().hasNotUsedIsoSplineElement(); return getNext().hasIsoSplineElement();
else else
return false; return false;
if(ref.r<iscs.rows && nextDirection.equals(NORTH)) if(ref.r<iscs.rows && nextDirection.equals(NORTH))
if(getNext()!=null) if(getNext()!=null)
return getNext().hasNotUsedIsoSplineElement(); return getNext().hasIsoSplineElement();
else else
return false; return false;
if(ref.c<iscs.cols && nextDirection.equals(EAST)) if(ref.c<iscs.cols && nextDirection.equals(EAST))
if(getNext()!=null) if(getNext()!=null)
return getNext().hasNotUsedIsoSplineElement(); return getNext().hasIsoSplineElement();
else else
return false; return false;
return false; return false;
...@@ -102,8 +101,6 @@ public class IsoSplineContainer { ...@@ -102,8 +101,6 @@ public class IsoSplineContainer {
public void createSplineElement(double isoLevel){ public void createSplineElement(double isoLevel){
ArrayList<Coordinate> splineCoords = new ArrayList(); ArrayList<Coordinate> splineCoords = new ArrayList();
ise = null;
used = false;
//System.out.println(ref); //System.out.println(ref);
int j=0; int j=0;
for(int i = 0; i<coords.size(); i++){ for(int i = 0; i<coords.size(); i++){
...@@ -119,17 +116,26 @@ public class IsoSplineContainer { ...@@ -119,17 +116,26 @@ public class IsoSplineContainer {
double range = (isoLevel - coord1.value)/(coord2.value - coord1.value); double range = (isoLevel - coord1.value)/(coord2.value - coord1.value);
double lat = range * (coord2.lat-coord1.lat) + coord1.lat; double lat = range * (coord2.lat-coord1.lat) + coord1.lat;
double lon = range * (coord2.lon-coord1.lon) + coord1.lon; double lon = range * (coord2.lon-coord1.lon) + coord1.lon;
splineCoords.add(new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel)); splineCoords.add(new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel, compass.get(i)));
directions.add(compass.get(i)); directions.add(compass.get(i));
} }
} }
if(splineCoords.size()==2){ ises = new IsoSplineElements(ref);
ise = new IsoSplineElement(splineCoords.get(0),splineCoords.get(1));
// System.out.println("Iso points: " + splineCoords.toString()); switch (splineCoords.size()) {
} case 2:
else{ ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
boolean ok = canCreateIsoSplineElement(isoLevel); break;
System.out.println("Wrong number of iso points: (" + ok + ")" + coords.toString()); case 3:
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
break;
case 4:
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(3)));
break;
default:
System.out.println("Wrong number of iso points: " + coords.toString());
break;
} }
} }
...@@ -147,19 +153,17 @@ public class IsoSplineContainer { ...@@ -147,19 +153,17 @@ public class IsoSplineContainer {
} }
public IsoSplineElement getIsoSplineElement(boolean used, int sortIndex){ public IsoSplineElement getIsoSplineElement(int sortIndex){
int i = 0; // TODO
IsoSplineElement ise = ises.get(i);
ises.remove(i);
ise.sortIndex=sortIndex; ise.sortIndex=sortIndex;
this.used=used;
return ise; return ise;
} }
public boolean hasNotUsedIsoSplineElement(){
return ise!=null && !used;
}
public boolean hasIsoSplineElement(){ public boolean hasIsoSplineElement(){
return ise!=null; return ises.size()>0;
} }
public boolean canCreateIsoSplineElement(double isoLevel){ public boolean canCreateIsoSplineElement(double isoLevel){
...@@ -196,11 +200,13 @@ public class IsoSplineContainer { ...@@ -196,11 +200,13 @@ public class IsoSplineContainer {
sb.append(coords.get(0).r); sb.append(coords.get(0).r);
sb.append(", "); sb.append(", ");
sb.append(coords.get(0).c); sb.append(coords.get(0).c);
sb.append("): "); sb.append("):\r\n");
for (int i = 0; i < coords.size(); i++) for (int i = 0; i < coords.size(); i++){
sb.append(coords.get(i).toString()); sb.append(coords.get(i).toString());
sb.append("\r\n");
}
sb.append("\t\n"); sb.append("\r\n");
return sb.toString(); return sb.toString();
} }
} }
......
...@@ -42,6 +42,7 @@ public class IsoSplineElement extends ArrayList<Coordinate> implements Comparab ...@@ -42,6 +42,7 @@ public class IsoSplineElement extends ArrayList<Coordinate> implements Comparab
return null; return null;
} }
@Override
public int compareTo(IsoSplineElement ise) { public int compareTo(IsoSplineElement ise) {
if(ise.sortIndex>sortIndex) if(ise.sortIndex>sortIndex)
return 1; return 1;
......
...@@ -28,6 +28,13 @@ public class IsoSplineElements extends ArrayList<IsoSplineElement> { ...@@ -28,6 +28,13 @@ public class IsoSplineElements extends ArrayList<IsoSplineElement> {
this.reference = reference; this.reference = reference;
} }
public IsoSplineElements(Coordinate reference){
this("NoName", Color.BLACK, reference);
}
public void sort(){ public void sort(){
Collections.sort(this, new Comparator<IsoSplineElement>() { Collections.sort(this, new Comparator<IsoSplineElement>() {
@Override @Override
......
...@@ -15,29 +15,28 @@ import isospline.Matrix; ...@@ -15,29 +15,28 @@ import isospline.Matrix;
* @author a001188 * @author a001188
*/ */
public class IsoSplineAnalyze { public class IsoSplineAnalyze {
public static final int SIZE=31;
public void calc(){ public void calc(){
Coordinate coord; Coordinate coord;
IsoSplineContainers iscs; IsoSplineContainers iscs;
Matrix matrix; Matrix matrix;
for(int i1 = 0; i1< SIZE; i1++)
for(int i2 = 0; i2< SIZE; i2=i2+2)
for(int i3 = 0; i3< SIZE; i3=i3+4)
for(int i4 = 0; i4< SIZE; i4=i4+8){
matrix = new Matrix(2,2); matrix = new Matrix(2,2);
matrix.add(new Coordinate(0.0, 0.0, 0, 0, i1)); matrix.add(new Coordinate(0.0, 0.0, 0, 0, 1.0, null));
matrix.add(new Coordinate(0.0, 1.0, 0, 1, i2)); matrix.add(new Coordinate(0.0, 1.0, 0, 1, 4.0, null));
matrix.add(new Coordinate(1.0, 0.0, 1, 0, i3)); matrix.add(new Coordinate(1.0, 0.0, 1, 0, 3.0, null));
matrix.add(new Coordinate(1.0, 1.0, 1, 1, i4)); matrix.add(new Coordinate(1.0, 1.0, 1, 1, 2.0, null));
double iso = 3.0001;
iscs = new IsoSplineContainers(1,1); iscs = new IsoSplineContainers(1,1);
iscs.createIsoSplineContainers(matrix); iscs.createIsoSplineContainers(matrix);
IsoSplineContainer isc = iscs.getIsoSplineContainer(0, 0); IsoSplineContainer isc = iscs.getIsoSplineContainer(0, 0);
if(isc.canCreateIsoSplineElement(15)) System.out.println(isc.toString());
System.out.println("JA " + isc.toString()); isc.createSplineElement(iso);
} if(isc.hasIsoSplineElement())
System.out.println(isc.getIsoSplineElement(0).toString());
if(isc.hasIsoSplineElement())
System.out.println(isc.getIsoSplineElement(1).toString());
} }
......
...@@ -73,7 +73,7 @@ public class JSONMatrix{ ...@@ -73,7 +73,7 @@ public class JSONMatrix{
Double lat = lonlatsArray.getDouble(1); Double lat = lonlatsArray.getDouble(1);
Double value = valuesArray.getDouble(i); Double value = valuesArray.getDouble(i);
updateStatistics(lon,lat,value); updateStatistics(lon,lat,value);
coord = new Coordinate(lon, lat, r, c, filteredValue(lon, lat, value)); coord = new Coordinate(lon, lat, r, c, filteredValue(lon, lat, value), null);
coords.add(coord); coords.add(coord);
if(c<cols-1){ if(c<cols-1){
c++; c++;
......
package shape; //package shape;
//
import java.io.BufferedReader; //import java.io.BufferedReader;
import java.io.File; //import java.io.File;
import java.io.FileReader; //import java.io.FileReader;
import java.io.Serializable; //import java.io.Serializable;
import java.util.HashMap; //import java.util.HashMap;
import java.util.Map; //import java.util.Map;
//
import org.geotools.data.DataStoreFactorySpi; //import org.geotools.data.DataStoreFactorySpi;
import org.geotools.data.DataUtilities; //import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction; //import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureStore; //import org.geotools.data.FeatureStore;
import org.geotools.data.Transaction; //import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore; //import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory; //import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.feature.FeatureCollection; //import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureCollections; //import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder; //import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder; //import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.referencing.crs.DefaultGeographicCRS; //import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.feature.simple.SimpleFeature; //import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType; //import org.opengis.feature.simple.SimpleFeatureType;
//
import com.vividsolutions.jts.geom.Coordinate; //import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory; //import com.vividsolutions.jts.geom.GeometryFactory;
//
public class Shape { //public class Shape {
//
public static void main(String[] args) throws Exception { // public static void main(String[] args) throws Exception {
File file = new File("inflasi3.csv"); // File file = new File("inflasi3.csv");
//
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection(); // FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection();
BufferedReader reader = new BufferedReader(new FileReader(file)); // BufferedReader reader = new BufferedReader(new FileReader(file));
SimpleFeatureType TYPE = null; // SimpleFeatureType TYPE = null;
try { // try {
String line = reader.readLine(); // String line = reader.readLine();
//
StringBuilder stringBuilder = new StringBuilder(); // StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("location:Point,"); // stringBuilder.append("location:Point,");
//
String[] headers = line.split("\\,"); // String[] headers = line.split("\\,");
for (String header : headers) { // for (String header : headers) {
stringBuilder.append("").append(header).append(":String,"); // stringBuilder.append("").append(header).append(":String,");
} // }
//
TYPE = DataUtilities.createType("Location", stringBuilder.substring(0, stringBuilder.toString().length() - 1)); // TYPE = DataUtilities.createType("Location", stringBuilder.substring(0, stringBuilder.toString().length() - 1));
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null); // GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
//
for (line = reader.readLine(); line != null; line = reader.readLine()) { // for (line = reader.readLine(); line != null; line = reader.readLine()) {
String split[] = line.split("\\,"); // String split[] = line.split("\\,");
//
String name = split[0]; // String name = split[0];
double latitude = Double.parseDouble(split[1]); // double latitude = Double.parseDouble(split[1]);
double longitude = Double.parseDouble(split[2]); // double longitude = Double.parseDouble(split[2]);
//
Object[] o = new Object[split.length+1]; // Object[] o = new Object[split.length+1];
for (int i = 2; i < o.length; i++) { // for (int i = 2; i < o.length; i++) {
o[i] = split[i-1]; // o[i] = split[i-1];
} // }
//
o[0] = factory.createPoint(new Coordinate(longitude, latitude)); // o[0] = factory.createPoint(new Coordinate(longitude, latitude));
o[1] = name; // o[1] = name;
//
SimpleFeature feature = SimpleFeatureBuilder.build(TYPE, o, null); // SimpleFeature feature = SimpleFeatureBuilder.build(TYPE, o, null);
//collection.add(feature); // //collection.add(feature);
} // }
} finally { // } finally {
reader.close(); // reader.close();
} // }
File newFile = new File("inflasi4.shp"); // File newFile = new File("inflasi4.shp");
//
DataStoreFactorySpi factory = new ShapefileDataStoreFactory(); // DataStoreFactorySpi factory = new ShapefileDataStoreFactory();
//
Map<String, Serializable> create = new HashMap<String, Serializable>(); // Map<String, Serializable> create = new HashMap<String, Serializable>();
create.put("url", newFile.toURI().toURL()); // create.put("url", newFile.toURI().toURL());
create.put("create spatial index", Boolean.TRUE); // create.put("create spatial index", Boolean.TRUE);
//
ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create); // ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
newDataStore.createSchema(TYPE); // newDataStore.createSchema(TYPE);
newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84); // newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
//
Transaction transaction = new DefaultTransaction("create"); // Transaction transaction = new DefaultTransaction("create");
//
String typeName = newDataStore.getTypeNames()[0]; // String typeName = newDataStore.getTypeNames()[0];
FeatureStore<SimpleFeatureType, SimpleFeature> featureStore; // FeatureStore<SimpleFeatureType, SimpleFeature> featureStore;
featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) newDataStore.getFeatureSource(typeName); // featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) newDataStore.getFeatureSource(typeName);
//
featureStore.setTransaction(transaction); // featureStore.setTransaction(transaction);
try { // try {
featureStore.addFeatures(collection); // featureStore.addFeatures(collection);
transaction.commit(); // transaction.commit();
} catch (Exception ex) { // } catch (Exception ex) {
ex.printStackTrace(); // ex.printStackTrace();
transaction.rollback(); // transaction.rollback();
} finally { // } finally {
transaction.close(); // transaction.close();
} // }
} // }
} //}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment