Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- OpenJump, BeanShell, MakeNewLayerFromDAT (teszt verzió)
- */
- /*
- public HashMap<Integer, LinkedHashMap<Integer, ArrayList<Integer>>> polySkeleton = new
- HashMap<Integer, // felulet_id
- LinkedHashMap<Integer, // felulet_sub_id
- ArrayList<Integer> // pont_id
- >
- >();
- */
- import java.io.*;
- import java.nio.file.*;
- import java.util.*;
- public class Point {
- public double y = 0;
- public double x = 0;
- public double m = 0;
- public void Point(double y, double x) throws IOException {
- Point(y,x,0);
- }
- public void Point(double y, double x, double m) throws IOException {
- this.y=y;
- this.x=x;
- this.m=m;
- }
- }
- { // Geomteriai elemek osztályai a DAT-ban
- public class Pont {
- public int pont_id = 0;
- public double pont_x = 0; // A pont EOV x koordinátája
- public double pont_y = 0; // A pont EOV y koordinátája
- public double pont_H = 0; // A pont EOMA magassága
- public int kozephiba_oszt_V = 0;
- public int kozephiba_oszt_M = 0;
- public void Pont(double x, double y, double h) throws IOException {
- this.pont_x=x;
- this.pont_y=y;
- this.pont_H=h;
- }
- }
- public class HatarVonal {
- public int hatarvonal_id = 0;
- public int hvsub_id = 0; // Alazonosító sorszám az egy határvonalat alkotó pontpárok (szakaszok) megkülönböztetésére
- public int pont_id_1 = 0;
- public int pont_id_2 = 0;
- public int osszekot_mod = 0;
- public int osszekot_id = 0;
- }
- public class Hatar {
- public int hatar_id = 0;
- public int hsub_id = 0; // Alazonosító sorszám az egy határt alkotó határvonalak megkülönböztetésére
- public int hatarvonal_id = 0;
- public char irany_valt = "";
- }
- public class Felulet {
- public int felulet_id = 0;
- public int subfel_id = 0; // Alazonosító sorszám a felületet alkotó valamely külső határ (és annak belső határai) megkülönböztetésére az ugyanazt a felületet alkotó többi külső határtól (és azok külső határaitól)
- public int hatar_id = 0;
- public char hatar_valt = "";
- }
- }
- { /* Minta a feluletek felépítéséhez
- Foktő (1342) BA02
- felulet_id=10370 + hatar_valt='-' (ismeretlen információt hordoz...)
- subfel_id=1
- hatar_id=7610 + hatar_valt='+' (külső határ)
- hsub_id irany_valt h.hatarvonal_id hvsub_id hv.p1_id hv.p2_id p.id
- 1 - 26354 1 207 1 1
- 2 - 26355 1 343 207 207
- 3 - 26353 1 1042 343 343
- 4 - 26356 1 1773 1042 1042
- 5 - 26338 1 1962 1773 1773
- hatar_id=7986 + hatar_valt='-' (belső határ)
- hsub_id irany_valt h.hatarvonal_id hvsub_id v.p1_id
- 1 + 3204 1 211 218 211
- 2 + 3202 1 218 224 218
- 3 + 24584 1 224 226 224
- 4 + 24585 1 226 228 226
- 5 - 26740 1 282 228 228
- subfel_id_2
- hatar_id=6888 + hatar_valt='+' (külső határ)
- hsub_id irany_valt h.hatarvonal_id hvsub_id v.p1_id
- 1 - 11362 1 24726 24725 24725
- 2 - 5880 1 24741 24726 24726
- 3 - 5879 1 24744 24741 24741
- 4 - 5882 1 24751 24744 24744
- 5 + 5883 1 24751 24756 24751
- */ }
- public class DAT {
- public String filename = "";
- public String header = "";
- public HashMap tables = new HashMap();
- public ArrayList wholeFileInArrayList = new ArrayList();
- public byte[] wholeFileInBytes;
- public HashMap byteIndex = new HashMap();
- public HashMap points = new HashMap();
- public void DAT(String filename) throws IOException {
- this.filename = filename;
- }
- public void openToHashMap() throws IOException {
- try {
- // https://techknowstudy.wordpress.com/2015/03/10/reading-a-file-through-bean-shell/
- fileReader=new FileReader(filename);
- bufferReader= new BufferedReader(fileReader);
- linenumber=0;
- while( (line=bufferReader.readLine()) != null ) {
- //if(line.equals("")) { continue; }
- line = line.trim().replaceAll("\\*$","");
- if ( ++linenumber == 1 ) {
- header = line;
- continue;
- }
- if(line.startsWith("T_")) {
- table = line;
- tables.put(table,new ArrayList());
- continue;
- } else {/*
- String[] words = line.split("\\*");
- for(i=0;i<words.length;i++){
- print(words[i]+"\t");
- }*/
- tables{table}.add(line);
- }
- };
- fileReader.close();
- bufferReader.close();
- for ( key : this.tables.keySet() ){ this.tables{key}.trimToSize(); }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void openToArrayList() throws IOException {
- try {
- fileReader=new FileReader(filename);
- bufferReader= new BufferedReader(fileReader);
- linenumber=0;
- while( (line=bufferReader.readLine()) != null ) {
- line = line.trim().replaceAll("\\*$","");
- if ( ++linenumber == 1 ) {
- header = line;
- continue;
- }
- wholeFileInArrayList.add(line);
- };
- fileReader.close();
- bufferReader.close();
- wholeFileInArrayList.trimToSize();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public ArrayList openToArrayList(String table) throws IOException {
- sorok = new ArrayList();
- check=0;
- try {
- fileReader=new FileReader(filename);
- bufferReader= new BufferedReader(fileReader);
- while( (line=bufferReader.readLine()) != null ) {
- line = line.trim().replaceAll("\\*$","");
- if ( line.equals(table) ) {
- check=1;
- continue;
- }
- if( line.startsWith("T_") && line.indexOf('*')==-1 ) {
- check=0;
- break;
- }
- if( check==1 ) {
- sorok.add(line);
- }
- };
- fileReader.close();
- bufferReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return sorok;
- }
- public byte[] openToByteArray() throws IOException {
- try {
- file = new File(filename);
- wholeFileInBytes = new byte[file.length()];
- inputStream = new FileInputStream(file);
- inputStream.read(wholeFileInBytes);
- //wholeFileInBytes = Files.readAllBytes(Paths.get(filename));
- } catch (Exception e) {
- System.out.println(e);
- }
- HashMap indexOfWholeFileInBytes = new HashMap();
- table="";
- lastEOL = 0;
- for ( int i = 0; i < wholeFileInBytes.length; i++ ) {
- if ( wholeFileInBytes[i]==0x0A ) {
- sor = ( new String ( Arrays.copyOfRange(wholeFileInBytes, lastEOL, i-1) ) ) .trim().replaceAll("\\*$","") ;
- if ( lastEOL==0 ) {
- header = sor;
- table = "Fejléc";
- }
- if ( sor.startsWith("T_") && sor.indexOf('*')==-1 ) {
- table = sor;
- indexOfWholeFileInBytes.put(table,new ArrayList());
- } else {
- //indexOfWholeFileInBytes{table}.add(lastEOL);
- //indexOfWholeFileInBytes{table}.add(i-1);
- }
- print ( table + " ¨"+sor+"¨" );
- //eoln.add(i);
- lastEOL=i+1;
- }
- }
- print (this.header);
- print ( indexOfWholeFileInBytes );
- return wholeFileInBytes;
- }
- public void setPoints() {
- for ( row : this.tables{"T_PONT"} ){
- //for ( row : openToArrayList("T_PONT") ){
- cols = row.split("\\*",-1);
- //points.put(cols[0],new Point(Double.parseDouble(cols[1]),Double.parseDouble(cols[2])/*,Double.parseDouble(cols[3])*/));
- if(cols[3].equals("")) {
- points.put(cols[0],new Coordinate(Double.parseDouble(cols[2]),Double.parseDouble(cols[1]),0));
- } else {
- points.put(cols[0],new Coordinate(Double.parseDouble(cols[2]),Double.parseDouble(cols[1]),Double.parseDouble(cols[3])));
- }
- }
- }
- } // end of DAT class.
- /*
- {
- dat = new DAT("q:\\OpenJUMP\\beanshell\\dat_ck_proba.dat");
- print ("Fájlnév: "+dat.filename );
- elotte=Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
- dat.openToHashMap();
- //dat.openToArrayList();
- utanna=Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
- print (elotte/1024/1024+" "+utanna/1024/1024+" : "+(utanna-elotte)/1024/1024+" [Mb]");
- print ( dat.header );
- for ( t : dat.tables.keySet() ) {
- print(t+": "+dat.tables{t}.size());
- }
- dat.setPoints();
- for ( key : dat.points.keySet() ) {
- print(key+": "+dat.points{key}.y+" "+dat.points{key}.x);
- }
- }*/
- {
- s1 = System.currentTimeMillis();
- filename = "c:\\Temp\\terkepek\\ck_proba.dat";
- filename = "q:\\OpenJUMP\\beanshell\\dat\\dat_kmet.dat";
- filename = "q:\\OpenJUMP\\beanshell\\dat\\dat_ck_proba.dat";
- dat = new DAT(filename);
- dat.openToHashMap();
- dat.setPoints();
- b = dat.openToByteArray();
- s2 = System.currentTimeMillis();
- print("eltelt idő: "+(s2-s1)+" ms\n");
- Random rand = new Random();
- randomString(int length) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0 ; i < length ; i++) sb.append((char)(64 + 27.0*Math.random()));
- return sb.toString();
- }
- schema = new FeatureSchema();
- schema.addAttribute("id",AttributeType.BIGINT);
- //schema.addAttribute("name",AttributeType.STRING);
- schema.addAttribute("geometry",AttributeType.GEOMETRY);
- print("Attributes of schema:");
- for ( name : schema.attributeNames ) {
- print(" - "+name+" ["+schema.getAttributeType(name)+"]");
- }
- dataset = new FeatureDataset(schema);
- for ( key : dat.points.keySet() ) {
- //coord = new Coordinate(dat.points{key}.y,dat.points{key}.x);
- //geom = new GeometryFactory().createPoint(coord);
- geom = new GeometryFactory().createPoint(dat.points{key});
- geom.setSRID(23700);
- bf = new BasicFeature(schema);
- bf.setGeometry(geom);
- //bf.setUserData("id", rand.nextInt(100)); // don't work...
- //bf.setUserData("name", randomString(5)); // don't work...
- bf.setAttribute("id", key);
- //bf.setAttribute("name", randomString(5));
- dataset.add(bf);
- }
- print("Dataset size: "+dataset.size());
- for ( f : dataset.getFeatures() ) {
- //print(" - "+f.getGeometry()+"\tid="+f.getAttribute(0)+"\tname="+f.getAttribute(1));
- }
- wc.layerManager.addLayer("DEMO","points",dataset);
- /*
- FeatureCollection points = FeatureDatasetFactory.createFromGeometry(geoms,schema);
- print("dataset size: "+points.size()+" [...]");
- wc.layerManager.addLayer("DEMO","more points",points);
- print("˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙");
- */
- s3 = System.currentTimeMillis();
- print("eltelt idő: "+(s3-s2)+" ms\n");
- print("+--------------------+\n"+"| END OF PROCESS |\n"+"+--------------------+\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement