Skip to content

Commit

Permalink
Change properties file to UTF8 and fix I18N and pom -> v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mukoki committed Mar 9, 2022
1 parent 66f0756 commit 99c2cfd
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 346 deletions.
2 changes: 1 addition & 1 deletion distro-zip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</dependencySet>
</dependencySets>
<!-- place deps in a extension lib/ subfolder
using fileset to easily include downloadeded jmat
using fileset to easily include downloaded jmat
system scope deps are ignored by dependencySet -->
<fileSets>
<fileSet>
Expand Down
19 changes: 9 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.openjump</groupId>
<artifactId>graph-toolbox</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -55,23 +55,22 @@
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.6.6</version>
<configuration>
<alwaysVerifyChecksum>true</alwaysVerifyChecksum>
</configuration>
<executions>
<execution>
<id>download jump-jgrapht</id>
<phase>compile</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/openjump-gis/jump-jgrapht/releases/download/2.0.0/jump-jgrapht-2.0.0.jar</url>
<sha1>b8e56dc1d3433f2777310732ab26eb5d84a0ded8</sha1>
<unpack>false</unpack>
<outputDirectory>${project.build.directory}/libs/</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<alwaysVerifyChecksum>true</alwaysVerifyChecksum>
<url>https://github.com/openjump-gis/jump-jgrapht/releases/download/2.0.0/jump-jgrapht-2.0.0.jar</url>
<sha1>b8e56dc1d3433f2777310732ab26eb5d84a0ded8</sha1>
<unpack>false</unpack>
<outputDirectory>${project.build.directory}/libs/</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
243 changes: 1 addition & 242 deletions src/main/java/fr/michaelm/jump/plugin/graph/CycleFinderPlugIn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 Micha&euml;l Michaud
* (C) 2022 Micha&euml;l Michaud
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -295,245 +295,6 @@ public void run(TaskMonitor monitor, PlugInContext context) {

Map<String,FeatureCollection> map = run(monitor);

/*
String INDEXATION_OF = I18NPlug.getI18N("CycleFinderPlugIn.indexation-of");
String POLYGONIZATION_OF = I18NPlug.getI18N("CycleFinderPlugIn.polygonization-of");
String ANALYSIS_OF = I18NPlug.getI18N("CycleFinderPlugIn.analysis-of");
String PROCESSED_CYCLES = I18NPlug.getI18N("CycleFinderPlugIn.processed-cycles");
String NB_OF_EDGES = I18NPlug.getI18N("CycleFinderPlugIn.number-of-edges");
String LENGTH = I18NPlug.getI18N("CycleFinderPlugIn.length");
String AREA = I18NPlug.getI18N("CycleFinderPlugIn.area");
String CONVEXITY = I18NPlug.getI18N("CycleFinderPlugIn.convexity");
String CONVEX = I18NPlug.getI18N("CycleFinderPlugIn.convex");
String CONCAVE = I18NPlug.getI18N("CycleFinderPlugIn.concave");
String CIRCULARITY = I18NPlug.getI18N("CycleFinderPlugIn.circularity");
String CYCLE_HOMOGENEITY = I18NPlug.getI18N("CycleFinderPlugIn.cycle-homogeneity");
String HOMOGENEOUS = I18NPlug.getI18N("CycleFinderPlugIn.homogeneous");
String ISOLATED = I18NPlug.getI18N("CycleFinderPlugIn.isolated");
String PENDANT = I18NPlug.getI18N("CycleFinderPlugIn.pendant");
String JUNCTION = I18NPlug.getI18N("CycleFinderPlugIn.junction");
String FORK = I18NPlug.getI18N("CycleFinderPlugIn.fork");
String HETEROGENEOUS = I18NPlug.getI18N("CycleFinderPlugIn.heterogeneous");
String AABABB = I18NPlug.getI18N("CycleFinderPlugIn.aababb");
String COMMENT = I18NPlug.getI18N("CycleFinderPlugIn.comment");
String NO_CYCLE_FOUND = I18NPlug.getI18N("CycleFinderPlugIn.no-cycle-found");
String HOMOGENEOUS_CYCLES = I18NPlug.getI18N("CycleFinderPlugIn.homogeneous-cycles");
String HETEROGENEOUS_CYCLES = I18NPlug.getI18N("CycleFinderPlugIn.heterogeneous-cycles");
//Layer layer = context.getLayerManager().getLayer(getStringParam(P_LAYER));
Layer layer = (Layer)getParameters().get(P_LAYER);
boolean dim3 = getBooleanParam(P_GRAPH_3D);
int min_features = getIntegerParam(P_MIN_FEATURES);
int max_features = getIntegerParam(P_MAX_FEATURE);
double max_length = getDoubleParam(P_MAX_LENGTH);
boolean all_homogeneous_cycles = getIntegerParam(P_DEGREE_FILTER) <= 0;
boolean isolated_cycles = (getIntegerParam(P_DEGREE_FILTER) & 1) == 1;
boolean pendant_cycles = (getIntegerParam(P_DEGREE_FILTER) & 2) == 2;
boolean junction_cycles = (getIntegerParam(P_DEGREE_FILTER) & 4) == 4;
boolean fork_cycles = (getIntegerParam(P_DEGREE_FILTER) & 8) == 8;
boolean use_attribute = (getStringParam(P_ATTRIBUTE) != null);
String attribute = getStringParam(P_ATTRIBUTE);
boolean ignore_empty = getBooleanParam(P_IGNORE_EMPTY);
boolean all_heterogeneous_cycles = getBooleanParam(P_FIND_ALL_HETEROGENEOUS);
boolean aab_abb_cycles_only = getBooleanParam(P_FIND_AAB_ABB);
monitor.allowCancellationRequests();
monitor.report(INDEXATION_OF + layer.getName() + "...");
FeatureSchema schema = new FeatureSchema();
schema.addAttribute("GEOMETRY", AttributeType.GEOMETRY);
schema.addAttribute(NB_OF_EDGES, AttributeType.INTEGER);
schema.addAttribute(LENGTH, AttributeType.DOUBLE);
schema.addAttribute(AREA, AttributeType.DOUBLE);
schema.addAttribute(CONVEXITY, AttributeType.STRING);
schema.addAttribute(CIRCULARITY, AttributeType.DOUBLE);
schema.addAttribute(CYCLE_HOMOGENEITY, AttributeType.STRING);
schema.addAttribute(COMMENT, AttributeType.STRING);
FeatureCollection homogeneous_cycles_FC = new FeatureDataset(schema);
FeatureCollection heterogeneous_cycles_FC = new FeatureDataset(schema);
// Filter and index input layer features
// Do not eliminate long features too early,
// because they can be used as incident edges
FeatureCollection filteredFC = layer.getFeatureCollectionWrapper();
if (use_attribute && ignore_empty) {
filteredFC = new FeatureDataset(filteredFC.getFeatureSchema());
for (Object f : layer.getFeatureCollectionWrapper().getFeatures()) {
if (((Feature)f).getAttribute(attribute)!=null &&
((Feature)f).getAttribute(attribute).toString().trim().length()>0) {
filteredFC.add(((Feature)f));
}
}
}
IndexedFeatureCollection ifc =
new IndexedFeatureCollection(filteredFC, new STRtree());
// Eliminate features with length < max before polygonization
// WARNING : a long feature can cut a short cycle into 2 long cycles
// ==> eliminating long features can produce small non-simple cycles
Collection<Geometry> geoms = new ArrayList<>();
// [2013-01-15] Eliminate line duplicates
Collection<Geometry> lines = new HashSet<>();
for (Object f : filteredFC.getFeatures()) {
Geometry geom = ((Feature)f).getGeometry();
if (geom.getLength()<=max_length) {
if (geom.getDimension() == 1) lines.add(geom.norm());
else geoms.add(geom);
}
}
geoms.addAll(lines);
monitor.report(POLYGONIZATION_OF + layer.getName() + "...");
// Polygonisation + selection of polygons with length < threshold
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geoms);
Collection<Geometry> pols = polygonizer.getPolygons();
geoms.clear();
for (Geometry p : pols) {
if ((p).getLength() <= max_length) geoms.add(p);
}
monitor.report(ANALYSIS_OF + layer.getName() + "...");
int count = 0;
// Loop over polygons representing cycles
for (Geometry g : geoms) {
// Select edges of the cycle and edges incident to the cycle
List<Feature> list = ifc.query(g.getEnvelopeInternal());
for (int i = list.size()-1 ; i>=0 ; i--) {
Geometry gfeature = (list.get(i)).getGeometry();
if (g.disjoint(gfeature)) list.remove(i);
}
// Creates the graph with features intersecting the polygon
Pseudograph<INode, FeatureAsEdge> graph =
GraphFactory.createUndirectedGraph(list, dim3);
// Graph node set and graph edges set
Set<INode> nodeSet = graph.vertexSet();
Set<FeatureAsEdge> edgeSet = graph.edgeSet();
// Subgraph containing only the cycle
Set<INode> cycleNodeSet = new HashSet<>();
for (INode n : nodeSet) {
if (n.getGeometry().intersects(g)) cycleNodeSet.add(n);
}
Graph<INode, FeatureAsEdge> cycle = new AsSubgraph<>(graph, cycleNodeSet);
Set<FeatureAsEdge> cycleEdgeSet = cycle.edgeSet();
// Eliminate too long ot too short cycles
if (cycleEdgeSet.size() < min_features || cycleEdgeSet.size() > max_features) continue;
String shape = g.equals(new ConvexHull(g).getConvexHull())?CONVEX:CONCAVE;
double area = g.getArea();
double perimeter = g.getLength();
// Circularity (100 = circular / 0 = linear)
double circularity = Math.floor(100.0*area*4.0*Math.PI/perimeter/perimeter);
// Build one feature for each cycle under/over size thresholds
Feature newf = new BasicFeature(schema);
newf.setGeometry(g);
newf.setAttribute(NB_OF_EDGES, cycleEdgeSet.size());
newf.setAttribute(CONVEXITY, shape);
newf.setAttribute(CIRCULARITY, circularity);
newf.setAttribute(LENGTH, perimeter);
newf.setAttribute(AREA, area);
// feature attributes found in cycle
Set<Object> attributeSet = new HashSet<>();
String NOATT = "DO_NOT_USE_ATTRIBUTE";
for (FeatureAsEdge e : cycleEdgeSet) {
if (use_attribute) attributeSet.add(e.getAttribute(attribute));
else attributeSet.add(NOATT);
}
// Case 0 : no attribute defined for cycle homogeneity
if (!use_attribute) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
int incident_edges = edgeSet.size() - cycleEdgeSet.size();
if (incident_edges == 0 && (all_homogeneous_cycles || isolated_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, ISOLATED);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges == 1 && (all_homogeneous_cycles || pendant_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, PENDANT);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges == 2 && (all_homogeneous_cycles || junction_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, JUNCTION);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges > 2 && (all_homogeneous_cycles || fork_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, FORK);
homogeneous_cycles_FC.add(newf);
}
}
// Case 1 : only one attribute value or !use_attribute
else if (attributeSet.size() == 1) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
Object atth = attributeSet.iterator().next();
int count_homogeneous_edges = 0;
for (FeatureAsEdge e : edgeSet) {
Object atte = use_attribute?e.getAttribute(attribute):NOATT;
if (atte.equals(atth)) count_homogeneous_edges++;
}
int incident_edges = count_homogeneous_edges - cycleEdgeSet.size();
if (incident_edges == 0 && (all_homogeneous_cycles || isolated_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, ISOLATED);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges == 1 && (all_homogeneous_cycles || pendant_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, PENDANT);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges == 2 && (all_homogeneous_cycles || junction_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, JUNCTION);
homogeneous_cycles_FC.add(newf);
}
else if (incident_edges > 2 && (all_homogeneous_cycles || fork_cycles)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HOMOGENEOUS);
newf.setAttribute(COMMENT, FORK);
homogeneous_cycles_FC.add(newf);
}
}
// Case 2 : use_attribute and several attribute values
else if (attributeSet.size() > 1 && (all_heterogeneous_cycles || aab_abb_cycles_only)) {
newf.setAttribute(CYCLE_HOMOGENEITY, HETEROGENEOUS);
//Object atth = attributeSet.iterator().next();
INode[] nodeArray = cycleNodeSet.toArray(new INode[0]);
if (all_heterogeneous_cycles) heterogeneous_cycles_FC.add(newf);
else { // aab_abb_cycles_only
for (int i = 0 ; i < nodeArray.length ; i++) {
//Map<Object,Integer> edgeMapI = new HashMap<Object,Integer>();
if (graph.edgesOf(nodeArray[i]).size() != 3) continue;
Map<Object,Integer> edgeMapI = incidentEdgeValues(nodeArray[i], graph, attribute);
if (edgeMapI.size() != 2) continue;
for (int j = 0 ; j < nodeArray.length ; j++) {
if (i==j || graph.edgesOf(nodeArray[j]).size() != 3) continue;
Map<Object,Integer> edgeMapJ = incidentEdgeValues(nodeArray[j], graph, attribute);
if (edgeMapI.keySet().equals(edgeMapJ.keySet()) && !edgeMapI.equals(edgeMapJ)) {
newf.setAttribute(COMMENT, AABABB);
heterogeneous_cycles_FC.add(newf);
}
}
}
}
}
count++;
monitor.report(count, geoms.size(), PROCESSED_CYCLES);
}
*/
String HOMOGENEOUS_CYCLES = i18n.get("CycleFinderPlugIn.homogeneous-cycles");
String HETEROGENEOUS_CYCLES = i18n.get("CycleFinderPlugIn.heterogeneous-cycles");
String NO_CYCLE_FOUND = i18n.get("CycleFinderPlugIn.no-cycle-found");
Expand Down Expand Up @@ -583,8 +344,6 @@ Map<String, FeatureCollection> run(TaskMonitor monitor) {
String HOMOGENEOUS_CYCLES = i18n.get("CycleFinderPlugIn.homogeneous-cycles");
String HETEROGENEOUS_CYCLES = i18n.get("CycleFinderPlugIn.heterogeneous-cycles");

//Layer layer = context.getLayerManager().getLayer(getStringParam(P_LAYER));
//FeatureCollection fc = (FeatureCollection)getParameters().get(P_DATASET);
boolean dim3 = getBooleanParam(P_GRAPH_3D);
int min_features = getIntegerParam(P_MIN_FEATURES);
int max_features = getIntegerParam(P_MAX_FEATURE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2011 Micha&euml;l Michaud
* (C) 2022 Micha&euml;l Michaud
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -92,8 +92,6 @@ public class GraphComponentsPlugIn extends ThreadedBasePlugIn {
String IGNORE_EMPTY_TOOLTIP;
String DIM3;
String DIM3_TOOLTIP;
//String FUZZY;
//String FUZZY_TOOLTIP;
String RETURN_GRAPHS_AS;
String RETURN_GRAPHS_AS_TOOLTIP;
String POINT, MULTILINESTRING, SIMPLIFIED_MULTILINESTRING;
Expand All @@ -109,15 +107,6 @@ public class GraphComponentsPlugIn extends ThreadedBasePlugIn {
String NO_GRAPH;

private static final GeometryFactory DEFAULT_GEOMETRY_FACTORY = new GeometryFactory();
//Layer layer;
//String attribute;
//AttributeType attType;
//boolean use_attribute = false;
//boolean ignore_empty = true;
//boolean dim3 = false;
////double fuzzy = 0.0;
//String return_graphs_as = "Point";


public String getName() {return "Graph components PlugIn";}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2011 Micha&euml;l Michaud
* (C) 2022 Micha&euml;l Michaud
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -36,8 +36,10 @@
* <li>CycleFinderPlugIn : computes a graph from a linear network and find base cycles</li>
* </ul>
* @author Micha&euml;l Michaud
* @version 1.1.0 (2021-08-08)
* @version 2.0.1 (2022-03-09)
*/
//version 2.0.1 (2022-03-09) Resources encoding
//version 2.0.0 (2022-03-01) Complete refactoring for OpenJUMP 2.0
//version 1.1.0 (2021-08-08) Refactoring to use new I18N and FeatureInstaller
//version 1.0.0 (2021-04-10) Refactoring for OpenJUMP 2 / JTS 1.18.1+
// Rename StrahlerNumberPlugIn to StreamOrderPlugIn
Expand Down Expand Up @@ -73,7 +75,7 @@ public String getVersion() {
return "1.0.0 (2021-04-10)";
}

public void configure(PlugInContext context) throws Exception {
public void configure(PlugInContext context) {

boolean missing_libraries = false;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2011 Micha&euml;l Michaud
* (C) 2022 Micha&euml;l Michaud
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void run(TaskMonitor monitor, PlugInContext context) {
FeatureCollection reversedFeatures =
new FeatureDataset(layer.getFeatureCollectionWrapper().getFeatureSchema());

EditTransaction transaction = new EditTransaction(new LinkedHashSet<Feature>(),
EditTransaction transaction = new EditTransaction(new LinkedHashSet<>(),
HYDROGRAPHIC_NETWORK_ANALYSIS, layer, true, true, context.getLayerViewPanel().getContext());
for (Feature feature : fc.getFeatures()) {
if (set.contains(feature.getID())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenJUMP/graph i18n strings english version (default)
# Original version: Michaël Michaud, 2010-04-22
# Last modified : Michaël Michaud, 2010-04-22
# Original version: Michaël Michaud, 2010-04-22
# Last modified : Michaël Michaud, 2010-04-22

Layer = Layer
Feature = Feature
Expand Down
Loading

0 comments on commit 99c2cfd

Please sign in to comment.