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