Maintenant que nous avons créé notre librairie dynamique, il serait bon de la tester avant de tenter une installation.
Pour ce faire nous avons créé une boucle simple permettant la compilation et l'exécution des binaires compilé (en utilisant la classe java puis le binaire C correspondant). C'est ce que vous trouverez ci-dessous :
count=1; sep="########################################################################" ; for jf in $(find src/com/vividsolutions/jtsexample/ | grep .java); do echo $sep; echo "Test n° $count : $jf"; echo $sep; jc=$(echo $jf | sed "s:src.::g;s:.java::g;s:/:.:g") ; target=$(echo $jc | cut -d'.' -f5); echo $jf \($jc\) $target; gcj -L./ -ljts -O2 -classpath ./jts.jar $jf --main=$jc -o $target && \ echo $sep && \ echo "Executing in java mode" && \ time java $jc && \ echo && \ echo $sep && \ echo "Executing in C mode" && \ time LD_LIBRARY_PATH="./" ./$target && \ echo && \ echo $sep && \ echo; count=$(expr $count + 1); doneSi tout c'est passé correctement vous devriez obtenir des résultat équivalents à ceux fournis ci-dessous :
######################################################################## Test n° 1 : src/com/vividsolutions/jtsexample/geom/BasicExample.java ######################################################################## src/com/vividsolutions/jtsexample/geom/BasicExample.java (com.vividsolutions.jtsexample.geom.BasicExample) BasicExample ######################################################################## Executing in java mode Geometry 1: LINESTRING (0 0, 10 10, 20 20) Geometry 2: LINESTRING (0 0, 10 10, 20 20) G1 intersection G2: MULTILINESTRING ((0 0, 10 10), (10 10, 20 20)) real 0m0.299s user 0m0.230s sys 0m0.024s ######################################################################## Executing in C mode Geometry 1: LINESTRING (0 0, 10 10, 20 20) Geometry 2: LINESTRING (0 0, 10 10, 20 20) G1 intersection G2: MULTILINESTRING ((0 0, 10 10), (10 10, 20 20)) real 0m0.138s user 0m0.115s sys 0m0.023s ######################################################################## ######################################################################## Test n° 2 : src/com/vividsolutions/jtsexample/geom/ConstructionExample.java ######################################################################## src/com/vividsolutions/jtsexample/geom/ConstructionExample.java (com.vividsolutions.jtsexample.geom.ConstructionExample) ConstructionExample ######################################################################## Executing in java mode POINT (0 0) POINT (0 0) MULTIPOINT (0 0, 1 1) real 0m0.194s user 0m0.153s sys 0m0.023s ######################################################################## Executing in C mode POINT (0 0) POINT (0 0) MULTIPOINT (0 0, 1 1) real 0m0.139s user 0m0.118s sys 0m0.021s ######################################################################## ######################################################################## Test n° 7 : src/com/vividsolutions/jtsexample/geom/PrecisionModelExample.java ######################################################################## src/com/vividsolutions/jtsexample/geom/PrecisionModelExample.java (com.vividsolutions.jtsexample.geom.PrecisionModelExample) PrecisionModelExample ######################################################################## Executing in java mode ------------------------------------------- Example 1 shows roundoff from computing in different precision models A = POLYGON ((60 180, 160 260, 240 80, 60 180)) B = POLYGON ((200 260, 280 160, 80 100, 200 260)) Running example using Precision Model = Floating A intersection B = POLYGON ((174.88372093023256 226.51162790697674, 213.33333333333334 140, 160.5194805194805 124.15584415584415, 116.47058823529412 148.62745098039215, 174.88372093023256 226.51162790697674)) Running example using Precision Model = Floating-Single A intersection B = POLYGON ((174.883728 226.511627, 213.333328 140, 160.519485 124.155846, 116.470589 148.627457, 174.883728 226.511627)) Running example using Precision Model = Fixed (Scale=1.0) A intersection B = POLYGON ((175 227, 213 140, 161 124, 116 149, 175 227)) ------------------------------------------- Example 2 shows that roundoff can change the topology of geometry computed in different precision models A = POLYGON ((0 0, 160 0, 160 1, 0 0)) B = POLYGON ((40 60, 40 -20, 140 -20, 140 60, 40 60)) ------------------------------------------- Running example using Precision Model = Floating A intersection B = MULTIPOLYGON (((40 0, 0 0, 40 0.25, 40 0)), ((140 0.875, 160 1, 160 0, 140 0, 140 0.875))) ------------------------------------------- Running example using Precision Model = Fixed (Scale=1.0) A intersection B = GEOMETRYCOLLECTION (LINESTRING (0 0, 40 0), POLYGON ((140 1, 160 1, 160 0, 140 0, 140 1))) real 0m0.303s user 0m0.237s sys 0m0.028s ######################################################################## Executing in C mode ------------------------------------------- Example 1 shows roundoff from computing in different precision models A = POLYGON ((60 180, 160 260, 240 80, 60 180)) B = POLYGON ((200 260, 280 160, 80 100, 200 260)) Running example using Precision Model = Floating A intersection B = POLYGON ((174.8837209302325561 226.5116279069767415, 213.3333333333333428 140, 160.5194805194805098 124.1558441558441501, 116.4705882352941159 148.6274509803921546, 174.8837209302325561 226.5116279069767415)) Running example using Precision Model = Floating-Single A intersection B = POLYGON ((174.883728 226.511627, 213.333328 140, 160.519485 124.155846, 116.470589 148.627457, 174.883728 226.511627)) Running example using Precision Model = Fixed (Scale=1.0) A intersection B = POLYGON ((175 227, 213 140, 161 124, 116 149, 175 227)) ------------------------------------------- Example 2 shows that roundoff can change the topology of geometry computed in different precision models A = POLYGON ((0 0, 160 0, 160 1, 0 0)) B = POLYGON ((40 60, 40 -20, 140 -20, 140 60, 40 60)) ------------------------------------------- Running example using Precision Model = Floating A intersection B = MULTIPOLYGON (((40 0, 0 0, 40 0.25, 40 0)), ((140 0.875, 160 1, 160 0, 140 0, 140 0.875))) ------------------------------------------- Running example using Precision Model = Fixed (Scale=1.0) A intersection B = GEOMETRYCOLLECTION (LINESTRING (0 0, 40 0), POLYGON ((140 1, 160 1, 160 0, 140 0, 140 1))) real 0m0.131s user 0m0.110s sys 0m0.021s ######################################################################## ######################################################################## Test n° 8 : src/com/vividsolutions/jtsexample/geom/SimpleMethodsExample.java ######################################################################## src/com/vividsolutions/jtsexample/geom/SimpleMethodsExample.java (com.vividsolutions.jtsexample.geom.SimpleMethodsExample) SimpleMethodsExample ######################################################################## Executing in java mode A = POLYGON ((40 100, 40 20, 120 20, 120 100, 40 100)) B = LINESTRING (20 80, 80 60, 100 140) A intersection B = LINESTRING (40 73.33333333333333, 80 60, 90 100) A relate C = 1F20F1102 real 0m0.297s user 0m0.223s sys 0m0.025s ######################################################################## Executing in C mode A = POLYGON ((40 100, 40 20, 120 20, 120 100, 40 100)) B = LINESTRING (20 80, 80 60, 100 140) A intersection B = LINESTRING (40 73.3333333333333285, 80 60, 90 100) A relate C = 1F20F1102 real 0m0.127s user 0m0.105s sys 0m0.022s ######################################################################## ######################################################################## Test n° 9 : src/com/vividsolutions/jtsexample/linearref/LinearRefExample.java ######################################################################## src/com/vividsolutions/jtsexample/linearref/LinearRefExample.java (com.vividsolutions.jtsexample.linearref.LinearRefExample) LinearRefExample ######################################################################## Executing in java mode ========================= Input Geometry: LINESTRING (0 0, 10 10, 20 20) Indices to extract: 1.0 10.0 Extracted Line: LINESTRING (0.7071067811865475 0.7071067811865475, 7.071067811865475 7.071067811865475) Indices of extracted line: 1.0 10.0 Midpoint of extracted line: (3.8890872965260117, 3.8890872965260117, NaN) ========================= Input Geometry: MULTILINESTRING ((0 0, 10 10), (20 20, 25 25, 30 40)) Indices to extract: 1.0 20.0 Extracted Line: MULTILINESTRING ((0.7071067811865475 0.7071067811865475, 10 10), (20 20, 24.14213562373095 24.14213562373095)) Indices of extracted line: 1.0 20.0 Midpoint of extracted line: (7.424621202458749, 7.424621202458749, NaN) real 0m0.193s user 0m0.155s sys 0m0.030s ######################################################################## Executing in C mode ========================= Input Geometry: LINESTRING (0 0, 10 10, 20 20) Indices to extract: 1.0 10.0 Extracted Line: LINESTRING (0.7071067811865474 0.7071067811865474, 7.0710678118654746 7.0710678118654746) Indices of extracted line: 1.0 10.0 Midpoint of extracted line: (3.8890872965260117, 3.8890872965260117, NaN) ========================= Input Geometry: MULTILINESTRING ((0 0, 10 10), (20 20, 25 25, 30 40)) Indices to extract: 1.0 20.0 Extracted Line: MULTILINESTRING ((0.7071067811865474 0.7071067811865474, 10 10), (20 20, 24.142135623730951 24.142135623730951)) Indices of extracted line: 1.0 20.0 Midpoint of extracted line: (7.424621202458749, 7.424621202458749, NaN) real 0m0.127s user 0m0.105s sys 0m0.022s ######################################################################## ######################################################################## Test n° 10 : src/com/vividsolutions/jtsexample/operation/distance/ClosestPointExample.java ######################################################################## src/com/vividsolutions/jtsexample/operation/distance/ClosestPointExample.java (com.vividsolutions.jtsexample.operation.distance.ClosestPointExample) distance ######################################################################## Executing in java mode ------------------------------------- Geometry A: POLYGON ((200 180, 60 140, 60 260, 200 180)) Geometry B: POINT (140 280) Distance = 57.05597791103589 Closest points: LINESTRING (111.6923076923077 230.46153846153845, 140 280) (distance = 57.055977911035896) ------------------------------------- Geometry A: POLYGON ((200 180, 60 140, 60 260, 200 180)) Geometry B: MULTIPOINT (140 280, 140 320) Distance = 57.05597791103589 Closest points: LINESTRING (111.6923076923077 230.46153846153845, 140 280) (distance = 57.055977911035896) ------------------------------------- Geometry A: LINESTRING (100 100, 200 100, 200 200, 100 200, 100 100) Geometry B: POINT (10 10) Distance = 127.27922061357856 Closest points: LINESTRING (100 100, 10 10) (distance = 127.27922061357856) ------------------------------------- Geometry A: LINESTRING (100 100, 200 200) Geometry B: LINESTRING (100 200, 200 100) Distance = 0.0 Closest points: LINESTRING (150 150, 150 150) (distance = 0.0) ------------------------------------- Geometry A: LINESTRING (100 100, 200 200) Geometry B: LINESTRING (150 121, 200 0) Distance = 20.506096654409877 Closest points: LINESTRING (135.5 135.5, 150 121) (distance = 20.506096654409877) ------------------------------------- Geometry A: POLYGON ((76 185, 125 283, 331 276, 324 122, 177 70, 184 155, 69 123, 76 185), (267 237, 148 248, 135 185, 223 189, 251 151, 286 183, 267 237)) Geometry B: LINESTRING (153 204, 185 224, 209 207, 238 222, 254 186) Distance = 13.788860460124573 Closest points: LINESTRING (139.4956500724988 206.78661188980183, 153 204) (distance = 13.788860460124573) ------------------------------------- Geometry A: POLYGON ((76 185, 125 283, 331 276, 324 122, 177 70, 184 155, 69 123, 76 185), (267 237, 148 248, 135 185, 223 189, 251 151, 286 183, 267 237)) Geometry B: LINESTRING (120 215, 185 224, 209 207, 238 222, 254 186) Distance = 0.0 Closest points: LINESTRING (120 215, 120 215) (distance = 0.0) real 0m0.247s user 0m0.175s sys 0m0.027s ######################################################################## Executing in C mode ------------------------------------- Geometry A: POLYGON ((200 180, 60 140, 60 260, 200 180)) Geometry B: POINT (140 280) Distance = 57.055977911035896 Closest points: LINESTRING (111.6923076923076934 230.4615384615384527, 140 280) (distance = 57.055977911035896) ------------------------------------- Geometry A: POLYGON ((200 180, 60 140, 60 260, 200 180)) Geometry B: MULTIPOINT (140 280, 140 320) Distance = 57.055977911035896 Closest points: LINESTRING (111.6923076923076934 230.4615384615384527, 140 280) (distance = 57.055977911035896) ------------------------------------- Geometry A: LINESTRING (100 100, 200 100, 200 200, 100 200, 100 100) Geometry B: POINT (10 10) Distance = 127.27922061357856 Closest points: LINESTRING (100 100, 10 10) (distance = 127.27922061357856) ------------------------------------- Geometry A: LINESTRING (100 100, 200 200) Geometry B: LINESTRING (100 200, 200 100) Distance = 0.0 Closest points: LINESTRING (150 150, 150 150) (distance = 0.0) ------------------------------------- Geometry A: LINESTRING (100 100, 200 200) Geometry B: LINESTRING (150 121, 200 0) Distance = 20.506096654409877 Closest points: LINESTRING (135.5 135.5, 150 121) (distance = 20.506096654409877) ------------------------------------- Geometry A: POLYGON ((76 185, 125 283, 331 276, 324 122, 177 70, 184 155, 69 123, 76 185), (267 237, 148 248, 135 185, 223 189, 251 151, 286 183, 267 237)) Geometry B: LINESTRING (153 204, 185 224, 209 207, 238 222, 254 186) Distance = 13.788860460124573 Closest points: LINESTRING (139.4956500724987904 206.7866118898018328, 153 204) (distance = 13.788860460124573) ------------------------------------- Geometry A: POLYGON ((76 185, 125 283, 331 276, 324 122, 177 70, 184 155, 69 123, 76 185), (267 237, 148 248, 135 185, 223 189, 251 151, 286 183, 267 237)) Geometry B: LINESTRING (120 215, 185 224, 209 207, 238 222, 254 186) Distance = 0.0 Closest points: LINESTRING (120 215, 120 215) (distance = 0.0) real 0m0.130s user 0m0.107s sys 0m0.023s ######################################################################## ######################################################################## Test n° 11 : src/com/vividsolutions/jtsexample/operation/linemerge/LineMergeExample.java ######################################################################## src/com/vividsolutions/jtsexample/operation/linemerge/LineMergeExample.java (com.vividsolutions.jtsexample.operation.linemerge.LineMergeExample) linemerge ######################################################################## Executing in java mode Lines formed (5): [LINESTRING (60 210, 30 190, 30 160, 40 150, 70 150, 100 180, 100 200, 90 210, 60 210), LINESTRING (160 310, 130 300, 100 290, 70 270, 60 260, 50 240, 50 220, 60 210), LINESTRING (70 430, 100 430, 120 420, 140 400, 150 370, 160 340, 160 310), LINESTRING (160 310, 200 330, 220 340, 240 360, 260 390, 260 410, 250 430), LINESTRING (160 310, 160 280, 160 250, 170 230, 180 210, 200 180, 220 160, 240 150, 270 150, 290 170)] real 0m0.299s user 0m0.240s sys 0m0.031s ######################################################################## Executing in C mode Lines formed (5): [LINESTRING (60 210, 30 190, 30 160, 40 150, 70 150, 100 180, 100 200, 90 210, 60 210), LINESTRING (160 310, 130 300, 100 290, 70 270, 60 260, 50 240, 50 220, 60 210), LINESTRING (70 430, 100 430, 120 420, 140 400, 150 370, 160 340, 160 310), LINESTRING (160 310, 200 330, 220 340, 240 360, 260 390, 260 410, 250 430), LINESTRING (160 310, 160 280, 160 250, 170 230, 180 210, 200 180, 220 160, 240 150, 270 150, 290 170)] real 0m0.270s user 0m0.207s sys 0m0.044s ######################################################################## ######################################################################## Test n° 12 : src/com/vividsolutions/jtsexample/operation/polygonize/PolygonizeExample.java ######################################################################## src/com/vividsolutions/jtsexample/operation/polygonize/PolygonizeExample.java (com.vividsolutions.jtsexample.operation.polygonize.PolygonizeExample) polygonize ######################################################################## Executing in java mode Polygons formed (2): [POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221)), POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))] real 0m0.480s user 0m0.411s sys 0m0.047s ######################################################################## Executing in C mode Polygons formed (2): [POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98)), POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))] real 0m0.252s user 0m0.206s sys 0m0.045s ######################################################################## ######################################################################## Test n° 13 : src/com/vividsolutions/jtsexample/precision/EnhancedPrecisionOpExample.java ######################################################################## src/com/vividsolutions/jtsexample/precision/EnhancedPrecisionOpExample.java (com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample) EnhancedPrecisionOpExample ######################################################################## Executing in java mode This call to intersection will throw a topology exception due to robustness problems: com.vividsolutions.jts.geom.TopologyException: Directed Edge visited twice during ring-building at (708522.7796120486, 2402268.6542990115, NaN) at com.vividsolutions.jts.geomgraph.EdgeRing.computePoints(EdgeRing.java:141) at com.vividsolutions.jts.geomgraph.EdgeRing.Vous aurez noté que les test numérotés de 3 à 6 n'ont pas été stipulés ici. En effet, ils renvoient tous une erreur qui est simplement liée au fait que la classe java ne contient pas de méthode main ce qui implique que la compilation échoue. Néanmoins grâce à ces quelques vérifications vous pouvez être assuré que votre librairie dynamique est utilisable. Vous aurez noté au passage que l'exécution des binaires C générés sont plus rapide que leurs équivalents java.(EdgeRing.java:70) at com.vividsolutions.jts.operation.overlay.MaximalEdgeRing. (MaximalEdgeRing.java:65) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.buildMaximalEdgeRings(PolygonBuilder.java:106) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.add(PolygonBuilder.java:80) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.add(PolygonBuilder.java:69) at com.vividsolutions.jts.operation.overlay.OverlayOp.computeOverlay(OverlayOp.java:180) at com.vividsolutions.jts.operation.overlay.OverlayOp.getResultGeometry(OverlayOp.java:127) at com.vividsolutions.jts.operation.overlay.OverlayOp.overlayOp(OverlayOp.java:66) at com.vividsolutions.jts.geom.Geometry.intersection(Geometry.java:1051) at com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample.run(EnhancedPrecisionOpExample.java:77) at com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample.main(EnhancedPrecisionOpExample.java:53) Using EnhancedPrecisionOp allows the intersection to be performed with no errors: MULTIPOLYGON (((708653.498611049 2402311.54647056, 708657.0443590372 2402304.6290913913, 708522.7796120486 2402268.6542990115, 708653.498611049 2402311.54647056)), ((708258.7634430077 2402197.914011042, 708257.0393502527 2402206.5716 68428, 708257.0393502527 2402206.571668428, 708258.7634430077 2402197.9140110426, 708258.7634430077 2402197.914011042))) real 0m0.589s user 0m0.529s sys 0m0.049s ######################################################################## Executing in C mode This call to intersection will throw a topology exception due to robustness problems: com.vividsolutions.jts.geom.TopologyException: Directed Edge visited twice during ring-building at (708522.7796120486, 2402268.6542990115, NaN) at com.vividsolutions.jts.geomgraph.EdgeRing.computePoints(libjts.so) at com.vividsolutions.jts.geomgraph.EdgeRing. (libjts.so) at com.vividsolutions.jts.operation.overlay.MaximalEdgeRing. (libjts.so) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.buildMaximalEdgeRings(libjts.so) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.add(libjts.so) at com.vividsolutions.jts.operation.overlay.PolygonBuilder.add(libjts.so) at com.vividsolutions.jts.operation.overlay.OverlayOp.computeOverlay(libjts.so) at com.vividsolutions.jts.operation.overlay.OverlayOp.getResultGeometry(libjts.so) at com.vividsolutions.jts.operation.overlay.OverlayOp.overlayOp(libjts.so) at com.vividsolutions.jts.geom.Geometry.intersection(libjts.so) at com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample.run(EnhancedPrecisionOpExample) at com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample.main(EnhancedPrecisionOpExample) Using EnhancedPrecisionOp allows the intersection to be performed with no errors: MULTIPOLYGON (((708653.4986110490281134 2402311.5464705601334571, 708657.0443590371869504 2402304.6290913913398981, 708522.7796120486455038 2402268.6542990114539861, 708653.4986110490281134 2402311.5464705601334571)), ((708258.763443 0077159777 2402197.914011042099446, 708257.0393502527149394 2402206.5716684279032051, 708257.0393502527149394 2402206.5716684279032051, 708258.7634430077159777 2402197.9140110425651073, 708258.7634430077159777 2402197.914011042099446 ))) real 0m0.309s user 0m0.220s sys 0m0.052s ######################################################################## ######################################################################## Test n° 14 : src/com/vividsolutions/jtsexample/technique/LineStringSelfIntersections.java ######################################################################## src/com/vividsolutions/jtsexample/technique/LineStringSelfIntersections.java (com.vividsolutions.jtsexample.technique.LineStringSelfIntersections) LineStringSelfIntersections ######################################################################## Executing in java mode Line: LINESTRING (0 0, 10 10, 20 20) Self Intersections: GEOMETRYCOLLECTION EMPTY Line: LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60) Self Intersections: POINT (20 40) real 0m0.528s user 0m0.427s sys 0m0.051s ######################################################################## Executing in C mode Line: LINESTRING (0 0, 10 10, 20 20) Self Intersections: GEOMETRYCOLLECTION EMPTY Line: LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60) Self Intersections: POINT (20 40) real 0m0.251s user 0m0.203s sys 0m0.047s ######################################################################## ######################################################################## Test n° 15 : src/com/vividsolutions/jtsexample/technique/PolygonUnionUsingBuffer.java ######################################################################## src/com/vividsolutions/jtsexample/technique/PolygonUnionUsingBuffer.java (com.vividsolutions.jtsexample.technique.PolygonUnionUsingBuffer) PolygonUnionUsingBuffer ######################################################################## Executing in java mode POLYGON ((80 140, 80 200, 100 200, 100 260, 180 260, 180 240, 240 240, 240 160, 200 160, 200 140, 80 140)) real 0m0.531s user 0m0.470s sys 0m0.057s ######################################################################## Executing in C mode POLYGON ((80 140, 80 200, 100 200, 100 260, 180 260, 180 240, 240 240, 240 160, 200 160, 200 140, 80 140)) real 0m0.253s user 0m0.212s sys 0m0.039s ########################################################################