@@ -739,7 +739,6 @@ public String pointash3String(
739739 return h3Address ;
740740 }
741741
742- // New Geo Functions
743742 @ Procedure (name = "com.neo4jh3.multilineash3" , mode = Mode .READ )
744743 @ Description ("com.neo4jh3.multilineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes." )
745744 public Stream <H3LongAddress > multilineash3 (
@@ -817,7 +816,7 @@ public Stream<H3LongAddress> multilineash3(
817816 return listh3Address .stream ().map (H3LongAddress ::of );
818817 }
819818
820- // New Geo Functions
819+ // New Geo Procedures
821820 @ Procedure (name = "com.neo4jh3.multilineash3String" , mode = Mode .READ )
822821 @ Description ("com.neo4jh3.multilineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes." )
823822 public Stream <H3StringAddress > multilineash3String (
@@ -892,6 +891,159 @@ public Stream<H3StringAddress> multilineash3String(
892891 }
893892 return listh3Address .stream ().map (H3StringAddress ::of );
894893 }
894+
895+ @ Procedure (name = "com.neo4jh3.lineash3" , mode = Mode .READ )
896+ @ Description ("com.neo4jh3.lineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes." )
897+ public Stream <H3LongAddress > lineash3 (
898+ @ Name ("wktString" ) String wktString ,
899+ @ Name ("h3Res" ) Long h3Res ) throws InterruptedException
900+ {
901+ List <Long > listh3Address = new ArrayList <Long >();
902+ List <Long > gpCells = new ArrayList <Long >();
903+ Long h3Address = 0L ;
904+ Long h3StartAddress = 0L ;
905+ Long h3MidAddress = 0L ;
906+ Long h3EndAddress = 0L ;
907+ Double fromLat = 0.0 ;
908+ Double fromLon = 0.0 ;
909+ Double toLat = 0.0 ;
910+ Double toLon = 0.0 ;
911+ Double midLat = 0.0 ;
912+ Double midLon = 0.0 ;
913+ String mls = "" ;
914+
915+ if (h3 == null ) {
916+ throw new InterruptedException ("h3 failed to initialize" );
917+ }
918+
919+ final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res .intValue ();
920+
921+ try {
922+ if (h3Resolution > 0 && h3Resolution <= 15 ) {
923+ mls = wktString .replace ("LINESTRING((" , "" );
924+ mls = mls .replace (" (" ,"" );
925+ mls = mls .replace (")" ,"" );
926+ mls = mls .replace ("(" ,"" );
927+ String [] latlonPairs = mls .split ("," );
928+ for (int i = 0 ; i < latlonPairs .length ; i ++) {
929+ if (i > 0 ){
930+ fromLat = Double .valueOf (latlonPairs [i -1 ].split (" " )[0 ]);
931+ fromLon = Double .valueOf (latlonPairs [i -1 ].split (" " )[1 ]);
932+ toLat = Double .valueOf (latlonPairs [i ].split (" " )[0 ]);
933+ toLon = Double .valueOf (latlonPairs [i ].split (" " )[1 ]);
934+ midLat = (fromLat + toLat ) / 2 ;
935+ midLon = (fromLon + toLon ) / 2 ;
936+ h3StartAddress = h3 .latLngToCell (fromLat , fromLon , h3Resolution );
937+ h3MidAddress = h3 .latLngToCell (midLat , midLon , h3Resolution );
938+ h3EndAddress = h3 .latLngToCell (toLat , toLon , h3Resolution );
939+ try {
940+ gpCells = h3 .gridPathCells (h3StartAddress , h3MidAddress );
941+ for (int j = 0 ; j < gpCells .size (); j ++) {
942+ listh3Address .add (gpCells .get (j ));
943+ }
944+ gpCells .clear ();
945+ } catch (Exception e1 ){
946+ }
947+ try {
948+ gpCells = h3 .gridPathCells ((h3MidAddress ), h3EndAddress );
949+ for (int j = 0 ; j < gpCells .size (); j ++) {
950+ listh3Address .add (gpCells .get (j ));
951+ }
952+ gpCells .clear ();
953+ } catch (Exception e1 ){
954+
955+ }
956+
957+ }
958+ }
959+ } else {
960+ listh3Address = Collections .singletonList (-2L );
961+
962+ }
963+ } catch (Exception e ) {
964+ //System.out.println(e);
965+ listh3Address = Collections .singletonList (-1L );
966+ // TODO Auto-generated catch block
967+ //e.printStackTrace();
968+ }
969+ return listh3Address .stream ().map (H3LongAddress ::of );
970+ }
971+
972+ // New Geo Procedures
973+ @ Procedure (name = "com.neo4jh3.lineash3String" , mode = Mode .READ )
974+ @ Description ("com.neo4jh3.lineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes." )
975+ public Stream <H3StringAddress > lineash3String (
976+ @ Name ("wktString" ) String wktString ,
977+ @ Name ("h3Res" ) Long h3Res ) throws InterruptedException
978+ {
979+ List <String > listh3Address = new ArrayList <String >();
980+ List <String > gpCells = new ArrayList <String >();
981+ String h3StartAddress = "" ;
982+ String h3MidAddress = "" ;
983+ String h3EndAddress = "" ;
984+ Double fromLat = 0.0 ;
985+ Double fromLon = 0.0 ;
986+ Double toLat = 0.0 ;
987+ Double toLon = 0.0 ;
988+ Double midLat = 0.0 ;
989+ Double midLon = 0.0 ;
990+ String mls = "" ;
991+
992+ if (h3 == null ) {
993+ throw new InterruptedException ("h3 failed to initialize" );
994+ }
995+
996+ final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res .intValue ();
997+
998+ try {
999+ if (h3Resolution > 0 && h3Resolution <= 15 ) {
1000+ mls = wktString .replace ("LINESTRING((" , "" );
1001+ mls = mls .replace (" (" ,"" );
1002+ mls = mls .replace (")" ,"" );
1003+ mls = mls .replace ("(" ,"" );
1004+ String [] latlonPairs = mls .split ("," );
1005+ for (int i = 0 ; i < latlonPairs .length ; i ++) {
1006+ if (i > 0 ){
1007+ fromLat = Double .valueOf (latlonPairs [i -1 ].split (" " )[0 ]);
1008+ fromLon = Double .valueOf (latlonPairs [i -1 ].split (" " )[1 ]);
1009+ toLat = Double .valueOf (latlonPairs [i ].split (" " )[0 ]);
1010+ toLon = Double .valueOf (latlonPairs [i ].split (" " )[1 ]);
1011+ midLat = (fromLat + toLat ) / 2 ;
1012+ midLon = (fromLon + toLon ) / 2 ;
1013+ h3StartAddress = h3 .latLngToCellAddress (fromLat , fromLon , h3Resolution );
1014+ h3MidAddress = h3 .latLngToCellAddress (midLat , midLon , h3Resolution );
1015+ h3EndAddress = h3 .latLngToCellAddress (toLat , toLon , h3Resolution );
1016+ try {
1017+ gpCells = h3 .gridPathCells (h3StartAddress , h3MidAddress );
1018+ for (int j = 0 ; j < gpCells .size (); j ++) {
1019+ listh3Address .add (gpCells .get (j ));
1020+ }
1021+ gpCells .clear ();
1022+ } catch (Exception e1 ){
1023+ //listh3Address = Collections.singletonList("-1");
1024+ }
1025+ try {
1026+ gpCells = h3 .gridPathCells ((h3MidAddress ), h3EndAddress );
1027+ for (int j = 0 ; j < gpCells .size (); j ++) {
1028+ listh3Address .add (gpCells .get (j ));
1029+ }
1030+ gpCells .clear ();
1031+ } catch (Exception e1 ){
1032+ //listh3Address = Collections.singletonList("-1");
1033+ }
1034+ }
1035+ }
1036+ } else {
1037+ listh3Address = Collections .singletonList ("-2" );
1038+ }
1039+ } catch (Exception e ) {
1040+ //System.out.println(e);
1041+ listh3Address = Collections .singletonList ("-1" );
1042+ // TODO Auto-generated catch block
1043+ //e.printStackTrace();
1044+ }
1045+ return listh3Address .stream ().map (H3StringAddress ::of );
1046+ }
8951047 // Geography Functions
8961048
8971049 @ UserFunction (name = "com.neo4jh3.centeraswkb" )
0 commit comments