Skip to content

Commit

Permalink
Remove unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
mukoki committed Apr 10, 2022
1 parent 422b9b4 commit 749535c
Show file tree
Hide file tree
Showing 30 changed files with 919 additions and 372 deletions.
5 changes: 4 additions & 1 deletion etc/Readme.txt
Expand Up @@ -27,6 +27,8 @@ as (Component name - License name - License file in "licenses/" folder or link)
Commons Codec, Compress, Imaging, IO, Lang, Logging
- Apache License Version 2.0 - apache_license-2.0.txt
CTS - GNU Lesser General Public License (GNU LGPL)
Esri projection list (resources/coord_ref_sys/pe_list_projcs_geogcs)
- Apache License Version 2.0 - apache_license-2.0.txt
Extensible-TIFF-JAI (xtiff jai) - MIT License - MIT-license.txt
Icons (some original or based fully or in part on the following)
FAMFAMFAM Silk by http://www.famfamfam.com - CC BY 2.5
Expand Down Expand Up @@ -59,12 +61,13 @@ as (Component name - License name - License file in "licenses/" folder or link)
Splash Logo designed by Paola Zanetti (paoladorileo<AT>gmail.com)
Vertical Design used in the installer by Stefan Steiniger 2012
Netbeans swing outline - Apache License Version 2.0 - apache_license-2.0.txt
Outline Swing Component by Netbeans.org, GPL2 - gpl-2.txt
Postgresql JDBC driver - Postgresql BSD license - postgresql-BSD_license.txt
Simple Logging Facade for Java (SLF4J) - MIT License - MIT-license.txt
lib/slf4j-api-*.jar,slf4j-api-*.jar
Xerces2 Java Parser - Apache License Version 2.0 - apache_license-2.0.txt
XZ for Java - Public Domain
Outline Swing Component by Netbeans.org, GPL2 - gpl-2.txt


and the following plugins
( Component name - License name - License file in "licenses/" folder
Expand Down
Binary file added lib/ext/coord_ref_sys/pe_list_projcs_geogcs.zip
Binary file not shown.
102 changes: 102 additions & 0 deletions src/com/vividsolutions/jump/coordsys/EsriProj.java
@@ -0,0 +1,102 @@
package com.vividsolutions.jump.coordsys;

import com.vividsolutions.jump.io.CompressedFile;
import com.vividsolutions.jump.workbench.JUMPWorkbench;
import com.vividsolutions.jump.workbench.Logger;
import org.apache.commons.compress.archivers.ArchiveException;

import java.io.*;
import java.util.*;

/**
* This class is used to find the precise Esri prj string for a given srid.
*
* Prj strings are taken from https://github.com/Esri/projection-engine-db-doc,
* licensed under the Apache License, Version 2.0 (the "License").
*
* This class uses the two following files from the github repository :
* <ul>
* <li>/csv/pe_list_projcs.csv</li>
* <li>/csv/pe_list_geogcs.csv</li>
* </ul>
* The two files have been concatenated in a single file and zipped in a single file
* containing a single entry named pe_list_projcs_geogcs.csv.
*
* The file is not decompressed during installation process. Searching a prj from an id
* fast enough (< 1s including the decompression step). Once a prj has been searched, it
* is cached in a map and the second search takes no time.
*
* There is room for improvement : the Esri file contains also bounding boxes for each
* projection and the wkt2 version of its description. A reverse search function (from
* string to id) could be implemented).
*/
public class EsriProj {

// A cache to remember already used projection string
public static Map<Integer,String> PROJMAP = new HashMap<>();
// A cache to remember already used projection ids
public static Map<String,Integer> CODEMAP = new HashMap<>();

private static final File projfile = JUMPWorkbench.getInstance().getPlugInManager()
.findFileOrFolderInExtensionDirs("coord_ref_sys/pe_list_projcs_geogcs.zip");
private static final String entryName = "pe_list_projcs_geogcs.csv";


public static void main(String[] args) throws IOException, ArchiveException {
System.out.println(findProj(2154));
System.out.println(findProj(2154));
}


private static String[] tokenize(String line) {
List<String> tokens = new ArrayList<>(15);
boolean quoted = false;
StringBuilder sb = new StringBuilder();
char[] array = line.toCharArray();
for (int i = 0 ; i < array.length ; i++) {
char c = array[i];
if (c == ',' && !quoted) {
tokens.add(sb.toString());
sb.setLength(0);
} else if (c == ' ' && !quoted) {
// pass
} else if (c == '"' && array[i+1] != '"') {
quoted = !quoted;
} else {
sb.append(c);
if (c == '"' && array[i+1] != '"') i++;
}
}
tokens.add(sb.toString());
return tokens.toArray(new String[0]);
}

public static String findProj(final int id) throws IOException, ArchiveException {
//long t0 = System.currentTimeMillis();
String proj = PROJMAP.get(id);
if (proj == null) proj = PROJMAP.get(id);
if (proj == null) {
//InputStream fis = new FileInputStream(projfile);
//InputStream is = CompressedFile.getUncompressedStream(fis, entryName);
InputStream is = CompressedFile.openFile(projfile.getPath(), entryName);
BufferedReader br = new BufferedReader(new InputStreamReader(is));

Optional<String[]> tokens = br.lines()
.map(EsriProj::tokenize)
.filter(it -> it[0].equals("" + id) || it[1].equals("" + id))
.findFirst();
if (tokens.isPresent()) {
String[] r = tokens.get();
PROJMAP.put(id, r[4]);
proj = r[4];
}
}
//System.out.println("found in " + (System.currentTimeMillis()-t0) + " ms");
if (proj != null)
Logger.info("Found Esri prj file for srid " + id);
else
Logger.warn("No Esri prj file found for srid " + id);
return proj;
}

}
9 changes: 2 additions & 7 deletions src/com/vividsolutions/jump/io/CompressedFile.java
Expand Up @@ -35,13 +35,7 @@

import static com.vividsolutions.jump.util.FileUtil.close;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down Expand Up @@ -286,6 +280,7 @@ else if (isSevenZ(filePath)) {

}


public static boolean isCompressed(URI uri) {
String filepath = UriUtil.getFilePath(uri);
return hasCompressedFileExtension(filepath);
Expand Down
55 changes: 12 additions & 43 deletions src/com/vividsolutions/jump/io/ShapefileWriter.java
Expand Up @@ -31,7 +31,9 @@
*/
package com.vividsolutions.jump.io;

import com.vividsolutions.jump.coordsys.EsriProj;
import com.vividsolutions.jump.workbench.Logger;
import org.apache.commons.compress.compressors.CompressorException;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.*;
import com.vividsolutions.jump.I18N;
Expand All @@ -51,6 +53,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.*;


Expand Down Expand Up @@ -307,7 +310,7 @@ public void write(FeatureCollection featureCollection, DriverProperties dp) thro

String registry = dp.getProperty(DataSource.COORDINATE_SYSTEM_REGISTRY, "EPSG");
String code = dp.getProperty(DataSource.COORDINATE_SYSTEM_CODE, "0");
String prjString = getPrjString(path + fname_withoutextention + ".prj", registry, code);
String prjString = getPrjString(code);
if (prjString != null) {
try {
prjfname = path + fname_withoutextention + ".prj";
Expand Down Expand Up @@ -689,52 +692,18 @@ else if (columnType == AttributeType.STRING ||
dbf.close();
}

// Prepare prj writing for 1.12 version
private String getPrjString(String fname, String registry, String code)
throws Exception {
if (code.equals("0")) return null;
if (!code.matches("\\d+")) return null;
if (registry.equals("EPSG")) {
try {
Integer epsgCode = Integer.parseInt(code);
if (PRJ_MAP.containsKey(epsgCode)) return PRJ_MAP.get(epsgCode);
String esriString = getPrjStringFromEpsg(epsgCode);
PRJ_MAP.put(epsgCode, esriString);
return esriString;
} catch(Exception e) {
Logger.warn(e);
}
}
if (Class.forName("org.cts.CRSFactory") != null) {
org.cts.CRSFactory crsFactory = new org.cts.CRSFactory();
org.cts.registry.RegistryManager registryManager = crsFactory.getRegistryManager();
if (registry.equals("EPSG")) registryManager.addRegistry(new org.cts.registry.EPSGRegistry());
if (registry.equals("ESRI")) registryManager.addRegistry(new org.cts.registry.ESRIRegistry());
org.cts.crs.CoordinateReferenceSystem crs = crsFactory.getCRS(registry + ":" + code);
//System.out.println(crs.toWKT());
return crs.toWKT();
} else {
throw new Exception("Class org.cts.CRSFactory has not been found");
}
}

/** Get esri formatted string from epsg.io website if possible.*/
private String getPrjStringFromEpsg(Integer code) throws Exception {
String url = "https://epsg.io/" + code + ".esriwkt";
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
int status = connection.getResponseCode();
if (status != 200) throw new Exception("Request to " + url + " failed");
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while((inputLine = in.readLine())!=null) {
content.append(inputLine);
private String getPrjString(String code) throws Exception {
try {
int srid = Integer.parseInt(code);
return EsriProj.findProj(srid);
} catch(IOException e) {
Logger.warn(e);
return null;
}
connection.disconnect();
return content.toString();
}


private String removeCount(String s, int count) {
return s.substring(0, s.length()-Integer.toString(count).length());
}
Expand Down
11 changes: 7 additions & 4 deletions src/com/vividsolutions/jump/workbench/model/LayerTreeModel.java
Expand Up @@ -41,6 +41,8 @@
import com.vividsolutions.jump.util.SimpleTreeModel;
import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStyle;
import org.openjump.core.rasterimage.RasterColorMapSymbology;
import org.openjump.core.rasterimage.RasterHeatmapSymbology;
import org.openjump.core.rasterimage.RasterImageLayer;
import org.openjump.core.rasterimage.RasterSymbology;

Expand Down Expand Up @@ -275,14 +277,15 @@ else if (parent instanceof Layerable) {
else if (parent instanceof RasterImageLayer) {

RasterImageLayer rasterImageLayer = (RasterImageLayer)parent;
if(rasterImageLayer.getSymbology() != null && rasterImageLayer.getMetadata() != null) {
if(rasterImageLayer.getSymbology() != null && rasterImageLayer.getMetadata() != null
&& rasterImageLayer.getSymbology() instanceof RasterColorMapSymbology) {

RasterSymbology rasterSymbology = rasterImageLayer.getSymbology();
RasterColorMapSymbology rasterSymbology = (RasterColorMapSymbology)rasterImageLayer.getSymbology();
double bottomValue = rasterImageLayer.getMetadata().getStats().getMin(0);
double topValue = rasterImageLayer.getMetadata().getStats().getMax(0);
Double[] keys = rasterSymbology.getColorMapEntries_tm().keySet().toArray(new Double[0]);

if(!rasterImageLayer.getSymbology().getColorMapType().equals(RasterSymbology.TYPE_RAMP)) {
if(!rasterImageLayer.getSymbology().getType().equals(RasterColorMapSymbology.TYPE_RAMP)) {

List<RasterStyleValueIntv> styleValues_l = new ArrayList<>();

Expand All @@ -296,7 +299,7 @@ else if (parent instanceof RasterImageLayer) {
Color color = rasterSymbology.getColorMapEntries_tm().get(key);

styleValues_l.add(new RasterStyleValueIntv(
rasterSymbology.getColorMapType(),
rasterSymbology.getType(),
color,
key,
nextValue,
Expand Down
Expand Up @@ -490,6 +490,7 @@ private Collection<Configuration> findConfigurations(File plugInDirectory) {
}

} catch (IOException e) {
Logger.error("Configuration failed for " + file.getPath());
Logger.error(e);
} finally {
FileUtil.close(zipFile);
Expand Down
Expand Up @@ -57,6 +57,7 @@
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import org.openjump.core.rasterimage.RasterColorMapSymbology;
import org.openjump.core.rasterimage.RasterImageLayer;

import org.locationtech.jts.geom.Envelope;
Expand Down Expand Up @@ -496,11 +497,11 @@ public Component getTreeCellRendererComponent(JTree tree,

RasterStyleValueIntv rasterStyleValue = (RasterStyleValueIntv) value;

if(rasterStyleValue.getColorMapType().equals(RasterSymbology.TYPE_INTERVALS)) {
if(rasterStyleValue.getColorMapType().equals(RasterColorMapSymbology.TYPE_INTERVALS)) {
label.setText(
rasterStyleValue.getValue().floatValue() + "-" +
rasterStyleValue.getNextValue().floatValue());
} else if(rasterStyleValue.getColorMapType().equals(RasterSymbology.TYPE_SINGLE)) {
} else if(rasterStyleValue.getColorMapType().equals(RasterColorMapSymbology.TYPE_SINGLE)) {
label.setText(String.valueOf(rasterStyleValue.getValue().intValue()));
}
colorPanel.setLineColor(Color.BLACK);
Expand Down

0 comments on commit 749535c

Please sign in to comment.