repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java | OSMTablesFactory.createWayMemberTable | public static PreparedStatement createWayMemberTable(Connection connection, String wayMemberTable) throws SQLException {
try (Statement stmt = connection.createStatement()) {
StringBuilder sb = new StringBuilder("CREATE TABLE ");
sb.append(wayMemberTable);
sb.append("(ID_RELATION BIGINT, ID_WAY BIGINT, ROLE VARCHAR, WAY_ORDER INT);");
stmt.execute(sb.toString());
}
return connection.prepareStatement("INSERT INTO " + wayMemberTable + " VALUES ( ?,?,?,?);");
} | java | public static PreparedStatement createWayMemberTable(Connection connection, String wayMemberTable) throws SQLException {
try (Statement stmt = connection.createStatement()) {
StringBuilder sb = new StringBuilder("CREATE TABLE ");
sb.append(wayMemberTable);
sb.append("(ID_RELATION BIGINT, ID_WAY BIGINT, ROLE VARCHAR, WAY_ORDER INT);");
stmt.execute(sb.toString());
}
return connection.prepareStatement("INSERT INTO " + wayMemberTable + " VALUES ( ?,?,?,?);");
} | [
"public",
"static",
"PreparedStatement",
"createWayMemberTable",
"(",
"Connection",
"connection",
",",
"String",
"wayMemberTable",
")",
"throws",
"SQLException",
"{",
"try",
"(",
"Statement",
"stmt",
"=",
"connection",
".",
"createStatement",
"(",
")",
")",
"{",
"... | Create a table to store all way members.
@param connection
@param wayMemberTable
@return
@throws SQLException | [
"Create",
"a",
"table",
"to",
"store",
"all",
"way",
"members",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java#L290-L298 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java | OSMTablesFactory.createRelationMemberTable | public static PreparedStatement createRelationMemberTable(Connection connection, String relationMemberTable) throws SQLException {
try (Statement stmt = connection.createStatement()) {
StringBuilder sb = new StringBuilder("CREATE TABLE ");
sb.append(relationMemberTable);
sb.append("(ID_RELATION BIGINT, ID_SUB_RELATION BIGINT, ROLE VARCHAR, RELATION_ORDER INT);");
stmt.execute(sb.toString());
}
return connection.prepareStatement("INSERT INTO " + relationMemberTable + " VALUES ( ?,?,?,?);");
} | java | public static PreparedStatement createRelationMemberTable(Connection connection, String relationMemberTable) throws SQLException {
try (Statement stmt = connection.createStatement()) {
StringBuilder sb = new StringBuilder("CREATE TABLE ");
sb.append(relationMemberTable);
sb.append("(ID_RELATION BIGINT, ID_SUB_RELATION BIGINT, ROLE VARCHAR, RELATION_ORDER INT);");
stmt.execute(sb.toString());
}
return connection.prepareStatement("INSERT INTO " + relationMemberTable + " VALUES ( ?,?,?,?);");
} | [
"public",
"static",
"PreparedStatement",
"createRelationMemberTable",
"(",
"Connection",
"connection",
",",
"String",
"relationMemberTable",
")",
"throws",
"SQLException",
"{",
"try",
"(",
"Statement",
"stmt",
"=",
"connection",
".",
"createStatement",
"(",
")",
")",
... | Store all relation members
@param connection
@param relationMemberTable
@return
@throws SQLException | [
"Store",
"all",
"relation",
"members"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java#L308-L316 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java | OSMTablesFactory.dropOSMTables | public static void dropOSMTables(Connection connection, boolean isH2, String tablePrefix) throws SQLException {
TableLocation requestedTable = TableLocation.parse(tablePrefix, isH2);
String osmTableName = requestedTable.getTable();
String[] omsTables = new String[]{TAG, NODE, NODE_TAG, WAY, WAY_NODE, WAY_TAG, RELATION, RELATION_TAG, NODE_MEMBER, WAY_MEMBER, RELATION_MEMBER};
StringBuilder sb = new StringBuilder("drop table if exists ");
String omsTableSuffix = omsTables[0];
String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2);
sb.append(osmTable);
for (int i = 1; i < omsTables.length; i++) {
omsTableSuffix = omsTables[i];
osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2);
sb.append(",").append(osmTable);
}
try (Statement stmt = connection.createStatement()) {
stmt.execute(sb.toString());
}
} | java | public static void dropOSMTables(Connection connection, boolean isH2, String tablePrefix) throws SQLException {
TableLocation requestedTable = TableLocation.parse(tablePrefix, isH2);
String osmTableName = requestedTable.getTable();
String[] omsTables = new String[]{TAG, NODE, NODE_TAG, WAY, WAY_NODE, WAY_TAG, RELATION, RELATION_TAG, NODE_MEMBER, WAY_MEMBER, RELATION_MEMBER};
StringBuilder sb = new StringBuilder("drop table if exists ");
String omsTableSuffix = omsTables[0];
String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2);
sb.append(osmTable);
for (int i = 1; i < omsTables.length; i++) {
omsTableSuffix = omsTables[i];
osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2);
sb.append(",").append(osmTable);
}
try (Statement stmt = connection.createStatement()) {
stmt.execute(sb.toString());
}
} | [
"public",
"static",
"void",
"dropOSMTables",
"(",
"Connection",
"connection",
",",
"boolean",
"isH2",
",",
"String",
"tablePrefix",
")",
"throws",
"SQLException",
"{",
"TableLocation",
"requestedTable",
"=",
"TableLocation",
".",
"parse",
"(",
"tablePrefix",
",",
... | Drop the existing OSM tables used to store the imported OSM data
@param connection
@param isH2
@param tablePrefix
@throws SQLException | [
"Drop",
"the",
"existing",
"OSM",
"tables",
"used",
"to",
"store",
"the",
"imported",
"OSM",
"data"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMTablesFactory.java#L327-L343 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/topography/TINFeatureFactory.java | TINFeatureFactory.createTriangle | public static Triangle createTriangle(Geometry geom) throws IllegalArgumentException {
Coordinate[] coordinates = geom.getCoordinates();
if (coordinates.length != 4) {
throw new IllegalArgumentException("The geometry must be a triangle");
}
return new Triangle(coordinates[0],coordinates[1],coordinates[2]);
} | java | public static Triangle createTriangle(Geometry geom) throws IllegalArgumentException {
Coordinate[] coordinates = geom.getCoordinates();
if (coordinates.length != 4) {
throw new IllegalArgumentException("The geometry must be a triangle");
}
return new Triangle(coordinates[0],coordinates[1],coordinates[2]);
} | [
"public",
"static",
"Triangle",
"createTriangle",
"(",
"Geometry",
"geom",
")",
"throws",
"IllegalArgumentException",
"{",
"Coordinate",
"[",
"]",
"coordinates",
"=",
"geom",
".",
"getCoordinates",
"(",
")",
";",
"if",
"(",
"coordinates",
".",
"length",
"!=",
... | A factory to create a DTriangle from a Geometry
@param geom
@return
@throws IllegalArgumentException
If there are not exactly 3 coordinates in geom. | [
"A",
"factory",
"to",
"create",
"a",
"DTriangle",
"from",
"a",
"Geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/topography/TINFeatureFactory.java#L49-L55 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java | KMLGeometry.toKMLLineString | public static void toKMLLineString(LineString lineString, ExtrudeMode extrude, int altitudeModeEnum, StringBuilder sb) {
sb.append("<LineString>");
appendExtrude(extrude, sb);
appendAltitudeMode(altitudeModeEnum, sb);
appendKMLCoordinates(lineString.getCoordinates(), sb);
sb.append("</LineString>");
} | java | public static void toKMLLineString(LineString lineString, ExtrudeMode extrude, int altitudeModeEnum, StringBuilder sb) {
sb.append("<LineString>");
appendExtrude(extrude, sb);
appendAltitudeMode(altitudeModeEnum, sb);
appendKMLCoordinates(lineString.getCoordinates(), sb);
sb.append("</LineString>");
} | [
"public",
"static",
"void",
"toKMLLineString",
"(",
"LineString",
"lineString",
",",
"ExtrudeMode",
"extrude",
",",
"int",
"altitudeModeEnum",
",",
"StringBuilder",
"sb",
")",
"{",
"sb",
".",
"append",
"(",
"\"<LineString>\"",
")",
";",
"appendExtrude",
"(",
"ex... | Defines a connected set of line segments.
Syntax :
<LineString id="ID">
<!-- specific to LineString -->
<gx:altitudeOffset>0</gx:altitudeOffset> <!-- double -->
<extrude>0</extrude> <!-- boolean -->
<tessellate>0</tessellate> <!-- boolean -->
<altitudeMode>clampToGround</altitudeMode>
<!-- kml:altitudeModeEnum: clampToGround, relativeToGround, or absolute
-->
<!-- or, substitute gx:altitudeMode: clampToSeaFloor, relativeToSeaFloor
-->
<gx:drawOrder>0</gx:drawOrder> <!-- integer -->
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LineString>
Supported syntax :
<LineString>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LineString>
@param lineString | [
"Defines",
"a",
"connected",
"set",
"of",
"line",
"segments",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java#L140-L146 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java | KMLGeometry.toKMLPolygon | public static void toKMLPolygon(Polygon polygon, ExtrudeMode extrude, int altitudeModeEnum, StringBuilder sb) {
sb.append("<Polygon>");
appendExtrude(extrude, sb);
appendAltitudeMode(altitudeModeEnum, sb);
sb.append("<outerBoundaryIs>");
toKMLLinearRing(polygon.getExteriorRing(), extrude, altitudeModeEnum, sb);
sb.append("</outerBoundaryIs>");
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
sb.append("<innerBoundaryIs>");
toKMLLinearRing(polygon.getInteriorRingN(i), extrude, altitudeModeEnum, sb);
sb.append("</innerBoundaryIs>");
}
sb.append("</Polygon>");
} | java | public static void toKMLPolygon(Polygon polygon, ExtrudeMode extrude, int altitudeModeEnum, StringBuilder sb) {
sb.append("<Polygon>");
appendExtrude(extrude, sb);
appendAltitudeMode(altitudeModeEnum, sb);
sb.append("<outerBoundaryIs>");
toKMLLinearRing(polygon.getExteriorRing(), extrude, altitudeModeEnum, sb);
sb.append("</outerBoundaryIs>");
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
sb.append("<innerBoundaryIs>");
toKMLLinearRing(polygon.getInteriorRingN(i), extrude, altitudeModeEnum, sb);
sb.append("</innerBoundaryIs>");
}
sb.append("</Polygon>");
} | [
"public",
"static",
"void",
"toKMLPolygon",
"(",
"Polygon",
"polygon",
",",
"ExtrudeMode",
"extrude",
",",
"int",
"altitudeModeEnum",
",",
"StringBuilder",
"sb",
")",
"{",
"sb",
".",
"append",
"(",
"\"<Polygon>\"",
")",
";",
"appendExtrude",
"(",
"extrude",
",... | A Polygon is defined by an outer boundary and 0 or more inner boundaries.
The boundaries, in turn, are defined by LinearRings.
Syntax :
<Polygon id="ID">
<!-- specific to Polygon -->
<extrude>0</extrude> <!-- boolean -->
<tessellate>0</tessellate> <!-- boolean -->
<altitudeMode>clampToGround</altitudeMode>
<!-- kml:altitudeModeEnum: clampToGround, relativeToGround, or absolute
-->
<!-- or, substitute gx:altitudeMode: clampToSeaFloor, relativeToSeaFloor
-->
<outerBoundaryIs>
<LinearRing>
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LinearRing>
</innerBoundaryIs>
</Polygon>
Supported syntax :
<Polygon>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LinearRing>
</innerBoundaryIs>
</Polygon>
@param polygon | [
"A",
"Polygon",
"is",
"defined",
"by",
"an",
"outer",
"boundary",
"and",
"0",
"or",
"more",
"inner",
"boundaries",
".",
"The",
"boundaries",
"in",
"turn",
"are",
"defined",
"by",
"LinearRings",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java#L230-L243 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java | KMLGeometry.appendKMLCoordinates | public static void appendKMLCoordinates(Coordinate[] coords, StringBuilder sb) {
sb.append("<coordinates>");
for (int i = 0; i < coords.length; i++) {
Coordinate coord = coords[i];
sb.append(coord.x).append(",").append(coord.y);
if (!Double.isNaN(coord.z)) {
sb.append(",").append(coord.z);
}
if (i < coords.length - 1) {
sb.append(" ");
}
}
sb.append("</coordinates>");
} | java | public static void appendKMLCoordinates(Coordinate[] coords, StringBuilder sb) {
sb.append("<coordinates>");
for (int i = 0; i < coords.length; i++) {
Coordinate coord = coords[i];
sb.append(coord.x).append(",").append(coord.y);
if (!Double.isNaN(coord.z)) {
sb.append(",").append(coord.z);
}
if (i < coords.length - 1) {
sb.append(" ");
}
}
sb.append("</coordinates>");
} | [
"public",
"static",
"void",
"appendKMLCoordinates",
"(",
"Coordinate",
"[",
"]",
"coords",
",",
"StringBuilder",
"sb",
")",
"{",
"sb",
".",
"append",
"(",
"\"<coordinates>\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"coords",
".",
"l... | Build a string represention to kml coordinates
Syntax :
<coordinates>...</coordinates> <!-- lon,lat[,alt] tuples -->
@param coords | [
"Build",
"a",
"string",
"represention",
"to",
"kml",
"coordinates"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java#L282-L295 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java | KMLGeometry.appendExtrude | private static void appendExtrude(ExtrudeMode extrude, StringBuilder sb) {
if (extrude.equals(ExtrudeMode.TRUE)) {
sb.append("<extrude>").append(1).append("</extrude>");
} else if (extrude.equals(ExtrudeMode.FALSE)) {
sb.append("<extrude>").append(0).append("</extrude>");
}
} | java | private static void appendExtrude(ExtrudeMode extrude, StringBuilder sb) {
if (extrude.equals(ExtrudeMode.TRUE)) {
sb.append("<extrude>").append(1).append("</extrude>");
} else if (extrude.equals(ExtrudeMode.FALSE)) {
sb.append("<extrude>").append(0).append("</extrude>");
}
} | [
"private",
"static",
"void",
"appendExtrude",
"(",
"ExtrudeMode",
"extrude",
",",
"StringBuilder",
"sb",
")",
"{",
"if",
"(",
"extrude",
".",
"equals",
"(",
"ExtrudeMode",
".",
"TRUE",
")",
")",
"{",
"sb",
".",
"append",
"(",
"\"<extrude>\"",
")",
".",
"... | Append the extrude value
Syntax :
<extrude>0</extrude>
@param extrude
@param sb | [
"Append",
"the",
"extrude",
"value"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/KMLGeometry.java#L307-L313 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/GeometryTypeNameFromConstraint.java | GeometryTypeNameFromConstraint.getGeometryTypeNameFromConstraint | public static String getGeometryTypeNameFromConstraint(String constraint, int numericPrecision) {
int geometryTypeCode = GeometryTypeFromConstraint.geometryTypeFromConstraint(constraint, numericPrecision);
return SFSUtilities.getGeometryTypeNameFromCode(geometryTypeCode);
} | java | public static String getGeometryTypeNameFromConstraint(String constraint, int numericPrecision) {
int geometryTypeCode = GeometryTypeFromConstraint.geometryTypeFromConstraint(constraint, numericPrecision);
return SFSUtilities.getGeometryTypeNameFromCode(geometryTypeCode);
} | [
"public",
"static",
"String",
"getGeometryTypeNameFromConstraint",
"(",
"String",
"constraint",
",",
"int",
"numericPrecision",
")",
"{",
"int",
"geometryTypeCode",
"=",
"GeometryTypeFromConstraint",
".",
"geometryTypeFromConstraint",
"(",
"constraint",
",",
"numericPrecisi... | Parse the constraint and return the Geometry type name.
@param constraint Constraint on geometry type
@param numericPrecision of the geometry type
@return Geometry type | [
"Parse",
"the",
"constraint",
"and",
"return",
"the",
"Geometry",
"type",
"name",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/GeometryTypeNameFromConstraint.java#L49-L52 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_CoordDim.java | ST_CoordDim.getCoordinateDimension | public static Integer getCoordinateDimension(byte[] geom) throws IOException {
if (geom == null) {
return null;
}
return GeometryMetaData.getMetaDataFromWKB(geom).dimension;
} | java | public static Integer getCoordinateDimension(byte[] geom) throws IOException {
if (geom == null) {
return null;
}
return GeometryMetaData.getMetaDataFromWKB(geom).dimension;
} | [
"public",
"static",
"Integer",
"getCoordinateDimension",
"(",
"byte",
"[",
"]",
"geom",
")",
"throws",
"IOException",
"{",
"if",
"(",
"geom",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"GeometryMetaData",
".",
"getMetaDataFromWKB",
"(",
"g... | Returns the dimension of the coordinates of the given geometry.
@param geom Geometry
@return The dimension of the coordinates of the given geometry
@throws IOException | [
"Returns",
"the",
"dimension",
"of",
"the",
"coordinates",
"of",
"the",
"given",
"geometry",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_CoordDim.java#L52-L57 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_BoundingCircleCenter.java | ST_BoundingCircleCenter.getCircumCenter | public static Point getCircumCenter(Geometry geometry) {
if(geometry == null || geometry.getNumPoints() == 0) {
return null;
}
return geometry.getFactory().createPoint(new MinimumBoundingCircle(geometry).getCentre());
} | java | public static Point getCircumCenter(Geometry geometry) {
if(geometry == null || geometry.getNumPoints() == 0) {
return null;
}
return geometry.getFactory().createPoint(new MinimumBoundingCircle(geometry).getCentre());
} | [
"public",
"static",
"Point",
"getCircumCenter",
"(",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
"||",
"geometry",
".",
"getNumPoints",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"geometry",
".",
"getF... | Compute the minimum bounding circle center of a geometry
@param geometry Any geometry
@return Minimum bounding circle center point | [
"Compute",
"the",
"minimum",
"bounding",
"circle",
"center",
"of",
"a",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_BoundingCircleCenter.java#L52-L57 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/internal/DBFDriver.java | DBFDriver.initDriverFromFile | public void initDriverFromFile(File dbfFile, String forceEncoding) throws IOException {
// Read columns from files metadata
this.dbfFile = dbfFile;
FileInputStream fis = new FileInputStream(dbfFile);
dbaseFileReader = new DbaseFileReader(fis.getChannel(), forceEncoding);
} | java | public void initDriverFromFile(File dbfFile, String forceEncoding) throws IOException {
// Read columns from files metadata
this.dbfFile = dbfFile;
FileInputStream fis = new FileInputStream(dbfFile);
dbaseFileReader = new DbaseFileReader(fis.getChannel(), forceEncoding);
} | [
"public",
"void",
"initDriverFromFile",
"(",
"File",
"dbfFile",
",",
"String",
"forceEncoding",
")",
"throws",
"IOException",
"{",
"// Read columns from files metadata",
"this",
".",
"dbfFile",
"=",
"dbfFile",
";",
"FileInputStream",
"fis",
"=",
"new",
"FileInputStrea... | Init file header for DBF File
@param dbfFile DBF File path
@param forceEncoding File encoding to use, null will use the file encoding provided in the file header
@throws IOException | [
"Init",
"file",
"header",
"for",
"DBF",
"File"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/internal/DBFDriver.java#L54-L59 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/internal/DBFDriver.java | DBFDriver.insertRow | @Override
public void insertRow(Object[] values) throws IOException {
checkWriter();
if(values.length != getDbaseFileHeader().getNumFields()) {
throw new IllegalArgumentException("Incorrect field count "+values.length+" expected "+getFieldCount());
}
try {
dbaseFileWriter.write(values);
} catch (DbaseFileException ex) {
throw new IOException(ex.getLocalizedMessage(), ex);
}
} | java | @Override
public void insertRow(Object[] values) throws IOException {
checkWriter();
if(values.length != getDbaseFileHeader().getNumFields()) {
throw new IllegalArgumentException("Incorrect field count "+values.length+" expected "+getFieldCount());
}
try {
dbaseFileWriter.write(values);
} catch (DbaseFileException ex) {
throw new IOException(ex.getLocalizedMessage(), ex);
}
} | [
"@",
"Override",
"public",
"void",
"insertRow",
"(",
"Object",
"[",
"]",
"values",
")",
"throws",
"IOException",
"{",
"checkWriter",
"(",
")",
";",
"if",
"(",
"values",
".",
"length",
"!=",
"getDbaseFileHeader",
"(",
")",
".",
"getNumFields",
"(",
")",
"... | Write a row
@param values Content, must be of the same type as declared in the header | [
"Write",
"a",
"row"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/internal/DBFDriver.java#L72-L83 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java | ST_RingBuffer.computePositiveRingBuffer | public static Geometry computePositiveRingBuffer(Geometry geom, double bufferDistance,
int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException {
Polygon[] buffers = new Polygon[numBuffer];
if (geom instanceof Polygon) {
//Work arround to manage polygon with hole
geom = geom.getFactory().createPolygon(((Polygon) geom).getExteriorRing().getCoordinateSequence());
}
Geometry previous = geom;
double distance = 0;
for (int i = 0; i < numBuffer; i++) {
distance += bufferDistance;
Geometry newBuffer = runBuffer(geom, distance, bufferParameters);
if (doDifference) {
buffers[i] = (Polygon) newBuffer.difference(previous);
} else {
buffers[i] = (Polygon) newBuffer;
}
previous = newBuffer;
}
return geom.getFactory().createMultiPolygon(buffers);
} | java | public static Geometry computePositiveRingBuffer(Geometry geom, double bufferDistance,
int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException {
Polygon[] buffers = new Polygon[numBuffer];
if (geom instanceof Polygon) {
//Work arround to manage polygon with hole
geom = geom.getFactory().createPolygon(((Polygon) geom).getExteriorRing().getCoordinateSequence());
}
Geometry previous = geom;
double distance = 0;
for (int i = 0; i < numBuffer; i++) {
distance += bufferDistance;
Geometry newBuffer = runBuffer(geom, distance, bufferParameters);
if (doDifference) {
buffers[i] = (Polygon) newBuffer.difference(previous);
} else {
buffers[i] = (Polygon) newBuffer;
}
previous = newBuffer;
}
return geom.getFactory().createMultiPolygon(buffers);
} | [
"public",
"static",
"Geometry",
"computePositiveRingBuffer",
"(",
"Geometry",
"geom",
",",
"double",
"bufferDistance",
",",
"int",
"numBuffer",
",",
"BufferParameters",
"bufferParameters",
",",
"boolean",
"doDifference",
")",
"throws",
"SQLException",
"{",
"Polygon",
... | Compute a ring buffer with a positive offset
@param geom
@param bufferDistance
@param numBuffer
@param bufferParameters
@param doDifference
@return
@throws SQLException | [
"Compute",
"a",
"ring",
"buffer",
"with",
"a",
"positive",
"offset"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java#L157-L177 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java | ST_RingBuffer.computeNegativeRingBuffer | public static Geometry computeNegativeRingBuffer(Geometry geom, double bufferDistance,
int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException {
Polygon[] buffers = new Polygon[numBuffer];
Geometry previous = geom;
double distance = 0;
if (geom instanceof Polygon) {
geom = ((Polygon) geom).getExteriorRing();
bufferParameters.setSingleSided(true);
}
for (int i = 0; i < numBuffer; i++) {
distance += bufferDistance;
Geometry newBuffer = runBuffer(geom, distance, bufferParameters);
if (i == 0) {
buffers[i] = (Polygon) newBuffer;
} else {
if (doDifference) {
buffers[i] = (Polygon) newBuffer.difference(previous);
} else {
buffers[i] = (Polygon) newBuffer;
}
}
previous = newBuffer;
}
return geom.getFactory().createMultiPolygon(buffers);
} | java | public static Geometry computeNegativeRingBuffer(Geometry geom, double bufferDistance,
int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException {
Polygon[] buffers = new Polygon[numBuffer];
Geometry previous = geom;
double distance = 0;
if (geom instanceof Polygon) {
geom = ((Polygon) geom).getExteriorRing();
bufferParameters.setSingleSided(true);
}
for (int i = 0; i < numBuffer; i++) {
distance += bufferDistance;
Geometry newBuffer = runBuffer(geom, distance, bufferParameters);
if (i == 0) {
buffers[i] = (Polygon) newBuffer;
} else {
if (doDifference) {
buffers[i] = (Polygon) newBuffer.difference(previous);
} else {
buffers[i] = (Polygon) newBuffer;
}
}
previous = newBuffer;
}
return geom.getFactory().createMultiPolygon(buffers);
} | [
"public",
"static",
"Geometry",
"computeNegativeRingBuffer",
"(",
"Geometry",
"geom",
",",
"double",
"bufferDistance",
",",
"int",
"numBuffer",
",",
"BufferParameters",
"bufferParameters",
",",
"boolean",
"doDifference",
")",
"throws",
"SQLException",
"{",
"Polygon",
... | Compute a ring buffer with a negative offset
@param geom
@param bufferDistance
@param numBuffer
@param bufferParameters
@param doDifference
@return
@throws SQLException | [
"Compute",
"a",
"ring",
"buffer",
"with",
"a",
"negative",
"offset"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java#L190-L214 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java | ST_RingBuffer.runBuffer | public static Geometry runBuffer(final Geometry geom, final double bufferSize,
final BufferParameters bufferParameters) throws SQLException {
return BufferOp.bufferOp(geom, bufferSize, bufferParameters);
} | java | public static Geometry runBuffer(final Geometry geom, final double bufferSize,
final BufferParameters bufferParameters) throws SQLException {
return BufferOp.bufferOp(geom, bufferSize, bufferParameters);
} | [
"public",
"static",
"Geometry",
"runBuffer",
"(",
"final",
"Geometry",
"geom",
",",
"final",
"double",
"bufferSize",
",",
"final",
"BufferParameters",
"bufferParameters",
")",
"throws",
"SQLException",
"{",
"return",
"BufferOp",
".",
"bufferOp",
"(",
"geom",
",",
... | Calculate the ring buffer
@param geom
@param bufferSize
@param bufferParameters
@return
@throws SQLException | [
"Calculate",
"the",
"ring",
"buffer"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_RingBuffer.java#L225-L228 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/predicates/ST_Covers.java | ST_Covers.covers | public static Boolean covers(Geometry geomA, Geometry geomB) {
if(geomA == null||geomB == null){
return null;
}
return geomA.covers(geomB);
} | java | public static Boolean covers(Geometry geomA, Geometry geomB) {
if(geomA == null||geomB == null){
return null;
}
return geomA.covers(geomB);
} | [
"public",
"static",
"Boolean",
"covers",
"(",
"Geometry",
"geomA",
",",
"Geometry",
"geomB",
")",
"{",
"if",
"(",
"geomA",
"==",
"null",
"||",
"geomB",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"geomA",
".",
"covers",
"(",
"geomB",
... | Returns true if no point in geometry B is outside geometry A.
@param geomA Geometry A
@param geomB Geometry B
@return True if no point in geometry B is outside geometry A | [
"Returns",
"true",
"if",
"no",
"point",
"in",
"geometry",
"B",
"is",
"outside",
"geometry",
"A",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/predicates/ST_Covers.java#L50-L55 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/TriMarkers.java | TriMarkers.getNormalVector | public static Vector3D getNormalVector(Triangle t) throws IllegalArgumentException {
if(Double.isNaN(t.p0.z) || Double.isNaN(t.p1.z) || Double.isNaN(t.p2.z)) {
throw new IllegalArgumentException("Z is required, cannot compute triangle normal of "+t);
}
double dx1 = t.p0.x - t.p1.x;
double dy1 = t.p0.y - t.p1.y;
double dz1 = t.p0.z - t.p1.z;
double dx2 = t.p1.x - t.p2.x;
double dy2 = t.p1.y - t.p2.y;
double dz2 = t.p1.z - t.p2.z;
return Vector3D.create(dy1*dz2 - dz1*dy2, dz1 * dx2 - dx1 * dz2, dx1 * dy2 - dy1 * dx2).normalize();
} | java | public static Vector3D getNormalVector(Triangle t) throws IllegalArgumentException {
if(Double.isNaN(t.p0.z) || Double.isNaN(t.p1.z) || Double.isNaN(t.p2.z)) {
throw new IllegalArgumentException("Z is required, cannot compute triangle normal of "+t);
}
double dx1 = t.p0.x - t.p1.x;
double dy1 = t.p0.y - t.p1.y;
double dz1 = t.p0.z - t.p1.z;
double dx2 = t.p1.x - t.p2.x;
double dy2 = t.p1.y - t.p2.y;
double dz2 = t.p1.z - t.p2.z;
return Vector3D.create(dy1*dz2 - dz1*dy2, dz1 * dx2 - dx1 * dz2, dx1 * dy2 - dy1 * dx2).normalize();
} | [
"public",
"static",
"Vector3D",
"getNormalVector",
"(",
"Triangle",
"t",
")",
"throws",
"IllegalArgumentException",
"{",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"t",
".",
"p0",
".",
"z",
")",
"||",
"Double",
".",
"isNaN",
"(",
"t",
".",
"p1",
".",
"z",... | Get the normal vector to this triangle, of length 1.
@param t input triangle
@return vector normal to the triangle. | [
"Get",
"the",
"normal",
"vector",
"to",
"this",
"triangle",
"of",
"length",
"1",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/TriMarkers.java#L171-L182 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/TriMarkers.java | TriMarkers.getSteepestVector | public static Vector3D getSteepestVector(final Vector3D normal, final double epsilon) {
if (Math.abs(normal.getX()) < epsilon && Math.abs(normal.getY()) < epsilon) {
return new Vector3D(0, 0, 0);
}
Vector3D slope;
if (Math.abs(normal.getX()) < epsilon) {
slope = new Vector3D(0, 1, -normal.getY() / normal.getZ());
} else if (Math.abs(normal.getY()) < epsilon) {
slope = new Vector3D(1, 0, -normal.getX() / normal.getZ());
} else {
slope = new Vector3D(normal.getX() / normal.getY(), 1,
-1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY()));
}
//We want the vector to be low-oriented.
if (slope.getZ() > epsilon) {
slope = new Vector3D(-slope.getX(), -slope.getY(), -slope.getZ());
}
//We normalize it
return slope.normalize();
} | java | public static Vector3D getSteepestVector(final Vector3D normal, final double epsilon) {
if (Math.abs(normal.getX()) < epsilon && Math.abs(normal.getY()) < epsilon) {
return new Vector3D(0, 0, 0);
}
Vector3D slope;
if (Math.abs(normal.getX()) < epsilon) {
slope = new Vector3D(0, 1, -normal.getY() / normal.getZ());
} else if (Math.abs(normal.getY()) < epsilon) {
slope = new Vector3D(1, 0, -normal.getX() / normal.getZ());
} else {
slope = new Vector3D(normal.getX() / normal.getY(), 1,
-1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY()));
}
//We want the vector to be low-oriented.
if (slope.getZ() > epsilon) {
slope = new Vector3D(-slope.getX(), -slope.getY(), -slope.getZ());
}
//We normalize it
return slope.normalize();
} | [
"public",
"static",
"Vector3D",
"getSteepestVector",
"(",
"final",
"Vector3D",
"normal",
",",
"final",
"double",
"epsilon",
")",
"{",
"if",
"(",
"Math",
".",
"abs",
"(",
"normal",
".",
"getX",
"(",
")",
")",
"<",
"epsilon",
"&&",
"Math",
".",
"abs",
"(... | Get the vector with the highest down slope in the plan.
@param normal
@param epsilon
@return the steepest vector. | [
"Get",
"the",
"vector",
"with",
"the",
"highest",
"down",
"slope",
"in",
"the",
"plan",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/TriMarkers.java#L190-L209 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/affine_transformations/ST_Scale.java | ST_Scale.scale | public static Geometry scale(Geometry geom, double xFactor, double yFactor) {
return scale(geom, xFactor, yFactor, 1.0);
} | java | public static Geometry scale(Geometry geom, double xFactor, double yFactor) {
return scale(geom, xFactor, yFactor, 1.0);
} | [
"public",
"static",
"Geometry",
"scale",
"(",
"Geometry",
"geom",
",",
"double",
"xFactor",
",",
"double",
"yFactor",
")",
"{",
"return",
"scale",
"(",
"geom",
",",
"xFactor",
",",
"yFactor",
",",
"1.0",
")",
";",
"}"
] | Scales the given geometry by multiplying the coordinates by the
indicated x and y scale factors, leaving the z-coordinate untouched.
@param geom Geometry
@param xFactor x scale factor
@param yFactor y scale factor
@return The geometry scaled by the given x and y scale factors | [
"Scales",
"the",
"given",
"geometry",
"by",
"multiplying",
"the",
"coordinates",
"by",
"the",
"indicated",
"x",
"and",
"y",
"scale",
"factors",
"leaving",
"the",
"z",
"-",
"coordinate",
"untouched",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/affine_transformations/ST_Scale.java#L54-L56 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/affine_transformations/ST_Scale.java | ST_Scale.scale | public static Geometry scale(Geometry geom, double xFactor, double yFactor, double zFactor) {
if (geom != null) {
Geometry scaledGeom = geom.copy();
for (Coordinate c : scaledGeom.getCoordinates()) {
c.setOrdinate(Coordinate.X, c.getOrdinate(Coordinate.X) * xFactor);
c.setOrdinate(Coordinate.Y, c.getOrdinate(Coordinate.Y) * yFactor);
c.setOrdinate(Coordinate.Z, c.getOrdinate(Coordinate.Z) * zFactor);
}
return scaledGeom;
} else {
return null;
}
} | java | public static Geometry scale(Geometry geom, double xFactor, double yFactor, double zFactor) {
if (geom != null) {
Geometry scaledGeom = geom.copy();
for (Coordinate c : scaledGeom.getCoordinates()) {
c.setOrdinate(Coordinate.X, c.getOrdinate(Coordinate.X) * xFactor);
c.setOrdinate(Coordinate.Y, c.getOrdinate(Coordinate.Y) * yFactor);
c.setOrdinate(Coordinate.Z, c.getOrdinate(Coordinate.Z) * zFactor);
}
return scaledGeom;
} else {
return null;
}
} | [
"public",
"static",
"Geometry",
"scale",
"(",
"Geometry",
"geom",
",",
"double",
"xFactor",
",",
"double",
"yFactor",
",",
"double",
"zFactor",
")",
"{",
"if",
"(",
"geom",
"!=",
"null",
")",
"{",
"Geometry",
"scaledGeom",
"=",
"geom",
".",
"copy",
"(",
... | Scales the given geometry by multiplying the coordinates by the
indicated x, y and z scale factors.
@param geom Geometry
@param xFactor x scale factor
@param yFactor y scale factor
@param zFactor z scale factor
@return The geometry scaled by the given x, y and z scale factors | [
"Scales",
"the",
"given",
"geometry",
"by",
"multiplying",
"the",
"coordinates",
"by",
"the",
"indicated",
"x",
"y",
"and",
"z",
"scale",
"factors",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/affine_transformations/ST_Scale.java#L68-L80 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java | ST_LineIntersector.lineIntersector | public static Geometry lineIntersector(Geometry inputLines, Geometry clipper) throws IllegalArgumentException {
if(inputLines == null||clipper == null){
return null;
}
if(inputLines.getDimension()==1){
MCIndexNoder mCIndexNoder = new MCIndexNoder();
mCIndexNoder.setSegmentIntersector(new IntersectionAdder(ROBUST_INTERSECTOR));
mCIndexNoder.computeNodes(getSegments(inputLines, clipper));
Collection nodedSubstring = mCIndexNoder.getNodedSubstrings();
GeometryFactory gf = inputLines.getFactory();
ArrayList<LineString> linestrings = new ArrayList<LineString>(nodedSubstring.size());
for (Iterator it = nodedSubstring.iterator(); it.hasNext();) {
SegmentString segment = (SegmentString) it.next();
//We keep only the segments of the input geometry
if((Integer)segment.getData()==0){
Coordinate[] cc = segment.getCoordinates();
cc = CoordinateArrays.atLeastNCoordinatesOrNothing(2, cc);
if (cc.length > 1) {
linestrings.add(gf.createLineString(cc));
}
}
}
if (linestrings.isEmpty()) {
return inputLines;
} else {
return gf.createMultiLineString(linestrings.toArray(new LineString[0]));
}}
throw new IllegalArgumentException("Split a " + inputLines.getGeometryType() + " by a " + clipper.getGeometryType() + " is not supported.");
} | java | public static Geometry lineIntersector(Geometry inputLines, Geometry clipper) throws IllegalArgumentException {
if(inputLines == null||clipper == null){
return null;
}
if(inputLines.getDimension()==1){
MCIndexNoder mCIndexNoder = new MCIndexNoder();
mCIndexNoder.setSegmentIntersector(new IntersectionAdder(ROBUST_INTERSECTOR));
mCIndexNoder.computeNodes(getSegments(inputLines, clipper));
Collection nodedSubstring = mCIndexNoder.getNodedSubstrings();
GeometryFactory gf = inputLines.getFactory();
ArrayList<LineString> linestrings = new ArrayList<LineString>(nodedSubstring.size());
for (Iterator it = nodedSubstring.iterator(); it.hasNext();) {
SegmentString segment = (SegmentString) it.next();
//We keep only the segments of the input geometry
if((Integer)segment.getData()==0){
Coordinate[] cc = segment.getCoordinates();
cc = CoordinateArrays.atLeastNCoordinatesOrNothing(2, cc);
if (cc.length > 1) {
linestrings.add(gf.createLineString(cc));
}
}
}
if (linestrings.isEmpty()) {
return inputLines;
} else {
return gf.createMultiLineString(linestrings.toArray(new LineString[0]));
}}
throw new IllegalArgumentException("Split a " + inputLines.getGeometryType() + " by a " + clipper.getGeometryType() + " is not supported.");
} | [
"public",
"static",
"Geometry",
"lineIntersector",
"(",
"Geometry",
"inputLines",
",",
"Geometry",
"clipper",
")",
"throws",
"IllegalArgumentException",
"{",
"if",
"(",
"inputLines",
"==",
"null",
"||",
"clipper",
"==",
"null",
")",
"{",
"return",
"null",
";",
... | Split a lineal geometry by a another geometry
@param inputLines
@param clipper
@return | [
"Split",
"a",
"lineal",
"geometry",
"by",
"a",
"another",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java#L64-L92 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java | ST_LineIntersector.addGeometryToSegments | public static void addGeometryToSegments(Geometry geometry, int flag, ArrayList<SegmentString> segments) {
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry component = geometry.getGeometryN(i);
if (component instanceof Polygon) {
add((Polygon) component, flag, segments);
} else if (component instanceof LineString) {
add((LineString) component, flag, segments);
}
}
} | java | public static void addGeometryToSegments(Geometry geometry, int flag, ArrayList<SegmentString> segments) {
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry component = geometry.getGeometryN(i);
if (component instanceof Polygon) {
add((Polygon) component, flag, segments);
} else if (component instanceof LineString) {
add((LineString) component, flag, segments);
}
}
} | [
"public",
"static",
"void",
"addGeometryToSegments",
"(",
"Geometry",
"geometry",
",",
"int",
"flag",
",",
"ArrayList",
"<",
"SegmentString",
">",
"segments",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"geometry",
".",
"getNumGeometries",
"... | Convert the a geometry as a list of segments and mark it with a flag
@param geometry
@param flag
@param segments | [
"Convert",
"the",
"a",
"geometry",
"as",
"a",
"list",
"of",
"segments",
"and",
"mark",
"it",
"with",
"a",
"flag"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java#L114-L123 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java | ST_LineIntersector.add | private static void add(Polygon poly, int flag, ArrayList<SegmentString> segments) {
add(poly.getExteriorRing(), flag, segments);
for (int j = 0; j < poly.getNumInteriorRing(); j++) {
add(poly.getInteriorRingN(j), flag, segments);
}
} | java | private static void add(Polygon poly, int flag, ArrayList<SegmentString> segments) {
add(poly.getExteriorRing(), flag, segments);
for (int j = 0; j < poly.getNumInteriorRing(); j++) {
add(poly.getInteriorRingN(j), flag, segments);
}
} | [
"private",
"static",
"void",
"add",
"(",
"Polygon",
"poly",
",",
"int",
"flag",
",",
"ArrayList",
"<",
"SegmentString",
">",
"segments",
")",
"{",
"add",
"(",
"poly",
".",
"getExteriorRing",
"(",
")",
",",
"flag",
",",
"segments",
")",
";",
"for",
"(",... | Convert a polygon as a list of segments and mark it with a flag
@param poly
@param flag
@param segments | [
"Convert",
"a",
"polygon",
"as",
"a",
"list",
"of",
"segments",
"and",
"mark",
"it",
"with",
"a",
"flag"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java#L131-L136 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java | ST_LineIntersector.add | private static void add(LineString line, int flag, ArrayList<SegmentString> segments) {
SegmentString ss = new NodedSegmentString(line.getCoordinates(),
flag);
segments.add(ss);
} | java | private static void add(LineString line, int flag, ArrayList<SegmentString> segments) {
SegmentString ss = new NodedSegmentString(line.getCoordinates(),
flag);
segments.add(ss);
} | [
"private",
"static",
"void",
"add",
"(",
"LineString",
"line",
",",
"int",
"flag",
",",
"ArrayList",
"<",
"SegmentString",
">",
"segments",
")",
"{",
"SegmentString",
"ss",
"=",
"new",
"NodedSegmentString",
"(",
"line",
".",
"getCoordinates",
"(",
")",
",",
... | Convert a linestring as a list of segments and mark it with a flag
@param line
@param flag
@param segments | [
"Convert",
"a",
"linestring",
"as",
"a",
"list",
"of",
"segments",
"and",
"mark",
"it",
"with",
"a",
"flag"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/split/ST_LineIntersector.java#L144-L148 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/ST_LocateAlong.java | ST_LocateAlong.locateAlong | public static MultiPoint locateAlong(Geometry geom,
double segmentLengthFraction,
double offsetDistance) {
if (geom == null) {
return null;
}
if (geom.getDimension() == 0) {
return null;
}
Set<Coordinate> result = new HashSet<Coordinate>();
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i);
if (subGeom instanceof Polygon) {
// Ignore hole
result.addAll(computePoints(((Polygon) subGeom).getExteriorRing().getCoordinates(),
segmentLengthFraction, offsetDistance));
} else if (subGeom instanceof LineString) {
result.addAll(computePoints(subGeom.getCoordinates(),
segmentLengthFraction, offsetDistance));
}
}
return geom.getFactory().createMultiPoint(
result.toArray(new Coordinate[0]));
} | java | public static MultiPoint locateAlong(Geometry geom,
double segmentLengthFraction,
double offsetDistance) {
if (geom == null) {
return null;
}
if (geom.getDimension() == 0) {
return null;
}
Set<Coordinate> result = new HashSet<Coordinate>();
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i);
if (subGeom instanceof Polygon) {
// Ignore hole
result.addAll(computePoints(((Polygon) subGeom).getExteriorRing().getCoordinates(),
segmentLengthFraction, offsetDistance));
} else if (subGeom instanceof LineString) {
result.addAll(computePoints(subGeom.getCoordinates(),
segmentLengthFraction, offsetDistance));
}
}
return geom.getFactory().createMultiPoint(
result.toArray(new Coordinate[0]));
} | [
"public",
"static",
"MultiPoint",
"locateAlong",
"(",
"Geometry",
"geom",
",",
"double",
"segmentLengthFraction",
",",
"double",
"offsetDistance",
")",
"{",
"if",
"(",
"geom",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"geom",
".",
"get... | Returns a MULTIPOINT containing points along the line segments of the
given geometry matching the specified segment length fraction and offset
distance.
@param geom Geometry
@param segmentLengthFraction Segment length fraction
@param offsetDistance Offset distance
@return A MULTIPOINT containing points along the line segments of the
given geometry matching the specified segment length fraction and offset
distance | [
"Returns",
"a",
"MULTIPOINT",
"containing",
"points",
"along",
"the",
"line",
"segments",
"of",
"the",
"given",
"geometry",
"matching",
"the",
"specified",
"segment",
"length",
"fraction",
"and",
"offset",
"distance",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/ST_LocateAlong.java#L67-L90 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/NetworkFunctions.java | NetworkFunctions.load | public static void load(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
try {
H2GISFunctions.registerFunction(st, function, "");
} catch (SQLException ex) {
// Catch to register other functions
LOGGER.error(ex.getLocalizedMessage(), ex);
}
}
} | java | public static void load(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
try {
H2GISFunctions.registerFunction(st, function, "");
} catch (SQLException ex) {
// Catch to register other functions
LOGGER.error(ex.getLocalizedMessage(), ex);
}
}
} | [
"public",
"static",
"void",
"load",
"(",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"for",
"(",
"Function",
"function",
":",
"getBuiltInsFunctions",
"(",
")",
")"... | Init H2 DataBase with the network functions
@param connection Active connection
@throws SQLException | [
"Init",
"H2",
"DataBase",
"with",
"the",
"network",
"functions"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/NetworkFunctions.java#L63-L73 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileReader.java | ShapefileReader.close | public void close() throws IOException {
if (channel != null && channel.isOpen()) {
channel.close();
}
channel = null;
header = null;
} | java | public void close() throws IOException {
if (channel != null && channel.isOpen()) {
channel.close();
}
channel = null;
header = null;
} | [
"public",
"void",
"close",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"channel",
"!=",
"null",
"&&",
"channel",
".",
"isOpen",
"(",
")",
")",
"{",
"channel",
".",
"close",
"(",
")",
";",
"}",
"channel",
"=",
"null",
";",
"header",
"=",
"nul... | Clean up any resources. Closes the channel.
@throws java.io.IOException
If errors occur while closing the channel. | [
"Clean",
"up",
"any",
"resources",
".",
"Closes",
"the",
"channel",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileReader.java#L127-L133 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileReader.java | ShapefileReader.geomAt | public Geometry geomAt(int offset) throws IOException {
// need to update position
buffer.position(offset);
// record header
buffer.skip(8);
// shape record is all little endian
buffer.order(ByteOrder.LITTLE_ENDIAN);
// read the type, handlers don't need it
ShapeType recordType = ShapeType.forID(buffer.getInt());
// this usually happens if the handler logic is bunk,
// but bad files could exist as well...
if (recordType != ShapeType.NULL && recordType != fileShapeType) {
throw new IllegalStateException("ShapeType changed illegally from "
+ fileShapeType + " to " + recordType);
}
return handler.read(buffer, recordType);
} | java | public Geometry geomAt(int offset) throws IOException {
// need to update position
buffer.position(offset);
// record header
buffer.skip(8);
// shape record is all little endian
buffer.order(ByteOrder.LITTLE_ENDIAN);
// read the type, handlers don't need it
ShapeType recordType = ShapeType.forID(buffer.getInt());
// this usually happens if the handler logic is bunk,
// but bad files could exist as well...
if (recordType != ShapeType.NULL && recordType != fileShapeType) {
throw new IllegalStateException("ShapeType changed illegally from "
+ fileShapeType + " to " + recordType);
}
return handler.read(buffer, recordType);
} | [
"public",
"Geometry",
"geomAt",
"(",
"int",
"offset",
")",
"throws",
"IOException",
"{",
"// need to update position",
"buffer",
".",
"position",
"(",
"offset",
")",
";",
"// record header",
"buffer",
".",
"skip",
"(",
"8",
")",
";",
"// shape record is all little... | Fetch the next record information.
@param offset
@throws java.io.IOException
@return The record instance associated with this reader. | [
"Fetch",
"the",
"next",
"record",
"information",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileReader.java#L142-L164 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DPerimeter.java | ST_3DPerimeter.st3Dperimeter | public static Double st3Dperimeter(Geometry geometry){
if(geometry==null){
return null;
}
if(geometry.getDimension()<2){
return 0d;
}
return compute3DPerimeter(geometry);
} | java | public static Double st3Dperimeter(Geometry geometry){
if(geometry==null){
return null;
}
if(geometry.getDimension()<2){
return 0d;
}
return compute3DPerimeter(geometry);
} | [
"public",
"static",
"Double",
"st3Dperimeter",
"(",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"geometry",
".",
"getDimension",
"(",
")",
"<",
"2",
")",
"{",
"return",
"0d",
... | Compute the 3D perimeter of a polygon or a multipolygon.
@param geometry
@return | [
"Compute",
"the",
"3D",
"perimeter",
"of",
"a",
"polygon",
"or",
"a",
"multipolygon",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DPerimeter.java#L51-L59 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DPerimeter.java | ST_3DPerimeter.compute3DPerimeter | private static double compute3DPerimeter(Geometry geometry) {
double sum = 0;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry subGeom = geometry.getGeometryN(i);
if (subGeom instanceof Polygon) {
sum += ST_3DLength.length3D(((Polygon) subGeom).getExteriorRing());
}
}
return sum;
} | java | private static double compute3DPerimeter(Geometry geometry) {
double sum = 0;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry subGeom = geometry.getGeometryN(i);
if (subGeom instanceof Polygon) {
sum += ST_3DLength.length3D(((Polygon) subGeom).getExteriorRing());
}
}
return sum;
} | [
"private",
"static",
"double",
"compute3DPerimeter",
"(",
"Geometry",
"geometry",
")",
"{",
"double",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"geometry",
".",
"getNumGeometries",
"(",
")",
";",
"i",
"++",
")",
"{",
"Geo... | Compute the 3D perimeter
@param geometry
@return | [
"Compute",
"the",
"3D",
"perimeter"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DPerimeter.java#L66-L75 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/DimensionFromConstraint.java | DimensionFromConstraint.dimensionFromConstraint | public static int dimensionFromConstraint(String constraint, String columnName) {
Matcher matcher = Z_CONSTRAINT_PATTERN.matcher(constraint);
if(matcher.find()) {
String extractedColumnName = matcher.group(1).replace("\"","").replace("`", "");
if(extractedColumnName.equalsIgnoreCase(columnName)) {
int constraint_value = Integer.valueOf(matcher.group(8));
String sign = matcher.group(5);
if("<>".equals(sign) || "!=".equals(sign)) {
constraint_value = constraint_value == 3 ? 2 : 3;
}
if("<".equals(sign)) {
constraint_value = 2;
}
if(">".equals(sign)) {
constraint_value = constraint_value == 2 ? 3 : 2;
}
return constraint_value;
}
}
return 2;
} | java | public static int dimensionFromConstraint(String constraint, String columnName) {
Matcher matcher = Z_CONSTRAINT_PATTERN.matcher(constraint);
if(matcher.find()) {
String extractedColumnName = matcher.group(1).replace("\"","").replace("`", "");
if(extractedColumnName.equalsIgnoreCase(columnName)) {
int constraint_value = Integer.valueOf(matcher.group(8));
String sign = matcher.group(5);
if("<>".equals(sign) || "!=".equals(sign)) {
constraint_value = constraint_value == 3 ? 2 : 3;
}
if("<".equals(sign)) {
constraint_value = 2;
}
if(">".equals(sign)) {
constraint_value = constraint_value == 2 ? 3 : 2;
}
return constraint_value;
}
}
return 2;
} | [
"public",
"static",
"int",
"dimensionFromConstraint",
"(",
"String",
"constraint",
",",
"String",
"columnName",
")",
"{",
"Matcher",
"matcher",
"=",
"Z_CONSTRAINT_PATTERN",
".",
"matcher",
"(",
"constraint",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")... | Public for Unit test
@param constraint Constraint value ex: ST_COORDIM(the_geom) = 3
@param columnName Column name ex:the_geom
@return The dimension constraint [2-3] | [
"Public",
"for",
"Unit",
"test"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/DimensionFromConstraint.java#L59-L79 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java | ST_3DLength.length3D | public static double length3D(Geometry geom) {
double sum = 0;
for (int i = 0; i < geom.getNumGeometries(); i++) {
sum += length3D((LineString) geom.getGeometryN(i));
}
return sum;
} | java | public static double length3D(Geometry geom) {
double sum = 0;
for (int i = 0; i < geom.getNumGeometries(); i++) {
sum += length3D((LineString) geom.getGeometryN(i));
}
return sum;
} | [
"public",
"static",
"double",
"length3D",
"(",
"Geometry",
"geom",
")",
"{",
"double",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"geom",
".",
"getNumGeometries",
"(",
")",
";",
"i",
"++",
")",
"{",
"sum",
"+=",
"lengt... | Returns the 3D length of the given geometry.
@param geom Geometry
@return The 3D length of the given geometry | [
"Returns",
"the",
"3D",
"length",
"of",
"the",
"given",
"geometry",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java#L67-L74 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java | ST_3DLength.length3D | public static double length3D(Polygon polygon) {
double length = 0.0;
length += length3D(polygon.getExteriorRing().getCoordinateSequence());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
length += length3D(polygon.getInteriorRingN(i));
}
return length;
} | java | public static double length3D(Polygon polygon) {
double length = 0.0;
length += length3D(polygon.getExteriorRing().getCoordinateSequence());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
length += length3D(polygon.getInteriorRingN(i));
}
return length;
} | [
"public",
"static",
"double",
"length3D",
"(",
"Polygon",
"polygon",
")",
"{",
"double",
"length",
"=",
"0.0",
";",
"length",
"+=",
"length3D",
"(",
"polygon",
".",
"getExteriorRing",
"(",
")",
".",
"getCoordinateSequence",
"(",
")",
")",
";",
"for",
"(",
... | Returns the 3D perimeter of the given polygon.
@param polygon Polygon
@return The 3D perimeter of the given polygon | [
"Returns",
"the",
"3D",
"perimeter",
"of",
"the",
"given",
"polygon",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java#L82-L89 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java | ST_3DLength.length3D | public static double length3D(CoordinateSequence points) {
// optimized for processing CoordinateSequences
int numberOfCoords = points.size();
// Points have no length.
if (numberOfCoords < 2) {
return 0.0;
}
Coordinate currentCoord = new Coordinate();
points.getCoordinate(0, currentCoord);
double x0 = currentCoord.x;
double y0 = currentCoord.y;
double z0 = currentCoord.z;
double length = 0.0;
for (int i = 1; i < numberOfCoords; i++) {
points.getCoordinate(i, currentCoord);
double x1 = currentCoord.x;
double y1 = currentCoord.y;
double z1 = currentCoord.z;
double dx = x1 - x0;
double dy = y1 - y0;
double dz;
// For 2D geometries, we want to return the 2D length.
if (Double.isNaN(z0) || Double.isNaN(z1)) {
dz = 0.0;
} else {
dz = z1 - z0;
}
length += Math.sqrt(dx * dx + dy * dy + dz * dz);
x0 = x1;
y0 = y1;
z0 = z1;
}
return length;
} | java | public static double length3D(CoordinateSequence points) {
// optimized for processing CoordinateSequences
int numberOfCoords = points.size();
// Points have no length.
if (numberOfCoords < 2) {
return 0.0;
}
Coordinate currentCoord = new Coordinate();
points.getCoordinate(0, currentCoord);
double x0 = currentCoord.x;
double y0 = currentCoord.y;
double z0 = currentCoord.z;
double length = 0.0;
for (int i = 1; i < numberOfCoords; i++) {
points.getCoordinate(i, currentCoord);
double x1 = currentCoord.x;
double y1 = currentCoord.y;
double z1 = currentCoord.z;
double dx = x1 - x0;
double dy = y1 - y0;
double dz;
// For 2D geometries, we want to return the 2D length.
if (Double.isNaN(z0) || Double.isNaN(z1)) {
dz = 0.0;
} else {
dz = z1 - z0;
}
length += Math.sqrt(dx * dx + dy * dy + dz * dz);
x0 = x1;
y0 = y1;
z0 = z1;
}
return length;
} | [
"public",
"static",
"double",
"length3D",
"(",
"CoordinateSequence",
"points",
")",
"{",
"// optimized for processing CoordinateSequences",
"int",
"numberOfCoords",
"=",
"points",
".",
"size",
"(",
")",
";",
"// Points have no length.",
"if",
"(",
"numberOfCoords",
"<",... | Computes the length of a LineString specified by a sequence of
coordinates.
@param points The coordinate sequence
@return The length of the corresponding LineString | [
"Computes",
"the",
"length",
"of",
"a",
"LineString",
"specified",
"by",
"a",
"sequence",
"of",
"coordinates",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DLength.java#L108-L148 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_SunPosition.java | ST_SunPosition.sunPosition | public static Geometry sunPosition(Geometry point, Date date) throws IllegalArgumentException{
if(point == null){
return null;
}
if (point instanceof Point) {
Coordinate coord = point.getCoordinate();
return point.getFactory().createPoint( SunCalc.getPosition(date, coord.y, coord.x));
} else {
throw new IllegalArgumentException("The sun position is computed according a point location.");
}
} | java | public static Geometry sunPosition(Geometry point, Date date) throws IllegalArgumentException{
if(point == null){
return null;
}
if (point instanceof Point) {
Coordinate coord = point.getCoordinate();
return point.getFactory().createPoint( SunCalc.getPosition(date, coord.y, coord.x));
} else {
throw new IllegalArgumentException("The sun position is computed according a point location.");
}
} | [
"public",
"static",
"Geometry",
"sunPosition",
"(",
"Geometry",
"point",
",",
"Date",
"date",
")",
"throws",
"IllegalArgumentException",
"{",
"if",
"(",
"point",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"point",
"instanceof",
"Point",
... | Return the sun position for a given date
@param point
@param date
@return
@throws IllegalArgumentException | [
"Return",
"the",
"sun",
"position",
"for",
"a",
"given",
"date"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_SunPosition.java#L68-L78 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java | ST_OffSetCurve.offsetCurve | public static Geometry offsetCurve(Geometry geometry, double offset, String parameters) {
if(geometry == null){
return null;
}
String[] buffParemeters = parameters.split("\\s+");
BufferParameters bufferParameters = new BufferParameters();
for (String params : buffParemeters) {
String[] keyValue = params.split("=");
if (keyValue[0].equalsIgnoreCase("endcap")) {
String param = keyValue[1];
if (param.equalsIgnoreCase("round")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND);
} else if (param.equalsIgnoreCase("flat") || param.equalsIgnoreCase("butt")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT);
} else if (param.equalsIgnoreCase("square")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE);
} else {
throw new IllegalArgumentException("Supported join values are round, flat, butt or square.");
}
} else if (keyValue[0].equalsIgnoreCase("join")) {
String param = keyValue[1];
if (param.equalsIgnoreCase("bevel")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL);
} else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE);
} else if (param.equalsIgnoreCase("round")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND);
} else {
throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round.");
}
} else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) {
bufferParameters.setMitreLimit(Double.valueOf(keyValue[1]));
} else if (keyValue[0].equalsIgnoreCase("quad_segs")) {
bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1]));
} else {
throw new IllegalArgumentException("Unknown parameters. Please read the documentation.");
}
}
return computeOffsetCurve(geometry, offset, bufferParameters);
} | java | public static Geometry offsetCurve(Geometry geometry, double offset, String parameters) {
if(geometry == null){
return null;
}
String[] buffParemeters = parameters.split("\\s+");
BufferParameters bufferParameters = new BufferParameters();
for (String params : buffParemeters) {
String[] keyValue = params.split("=");
if (keyValue[0].equalsIgnoreCase("endcap")) {
String param = keyValue[1];
if (param.equalsIgnoreCase("round")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND);
} else if (param.equalsIgnoreCase("flat") || param.equalsIgnoreCase("butt")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT);
} else if (param.equalsIgnoreCase("square")) {
bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE);
} else {
throw new IllegalArgumentException("Supported join values are round, flat, butt or square.");
}
} else if (keyValue[0].equalsIgnoreCase("join")) {
String param = keyValue[1];
if (param.equalsIgnoreCase("bevel")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL);
} else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE);
} else if (param.equalsIgnoreCase("round")) {
bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND);
} else {
throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round.");
}
} else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) {
bufferParameters.setMitreLimit(Double.valueOf(keyValue[1]));
} else if (keyValue[0].equalsIgnoreCase("quad_segs")) {
bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1]));
} else {
throw new IllegalArgumentException("Unknown parameters. Please read the documentation.");
}
}
return computeOffsetCurve(geometry, offset, bufferParameters);
} | [
"public",
"static",
"Geometry",
"offsetCurve",
"(",
"Geometry",
"geometry",
",",
"double",
"offset",
",",
"String",
"parameters",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"String",
"[",
"]",
"buffParemeters",
"="... | Return an offset line at a given distance and side from an input geometry
@param geometry the geometry
@param offset the distance
@param parameters the buffer parameters
@return | [
"Return",
"an",
"offset",
"line",
"at",
"a",
"given",
"distance",
"and",
"side",
"from",
"an",
"input",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java#L62-L101 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java | ST_OffSetCurve.computeOffsetCurve | public static Geometry computeOffsetCurve(Geometry geometry, double offset, BufferParameters bufferParameters) {
ArrayList<LineString> lineStrings = new ArrayList<LineString>();
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry subGeom = geometry.getGeometryN(i);
if (subGeom.getDimension() == 1) {
lineStringOffSetCurve(lineStrings, (LineString) subGeom, offset, bufferParameters);
} else {
geometryOffSetCurve(lineStrings, subGeom, offset, bufferParameters);
}
}
if (!lineStrings.isEmpty()) {
if (lineStrings.size() == 1) {
return lineStrings.get(0);
} else {
return geometry.getFactory().createMultiLineString(lineStrings.toArray(new LineString[0]));
}
}
return null;
} | java | public static Geometry computeOffsetCurve(Geometry geometry, double offset, BufferParameters bufferParameters) {
ArrayList<LineString> lineStrings = new ArrayList<LineString>();
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry subGeom = geometry.getGeometryN(i);
if (subGeom.getDimension() == 1) {
lineStringOffSetCurve(lineStrings, (LineString) subGeom, offset, bufferParameters);
} else {
geometryOffSetCurve(lineStrings, subGeom, offset, bufferParameters);
}
}
if (!lineStrings.isEmpty()) {
if (lineStrings.size() == 1) {
return lineStrings.get(0);
} else {
return geometry.getFactory().createMultiLineString(lineStrings.toArray(new LineString[0]));
}
}
return null;
} | [
"public",
"static",
"Geometry",
"computeOffsetCurve",
"(",
"Geometry",
"geometry",
",",
"double",
"offset",
",",
"BufferParameters",
"bufferParameters",
")",
"{",
"ArrayList",
"<",
"LineString",
">",
"lineStrings",
"=",
"new",
"ArrayList",
"<",
"LineString",
">",
... | Method to compute the offset line
@param geometry
@param offset
@param bufferParameters
@return | [
"Method",
"to",
"compute",
"the",
"offset",
"line"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java#L121-L139 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java | ST_OffSetCurve.lineStringOffSetCurve | public static void lineStringOffSetCurve(ArrayList<LineString> list, LineString lineString, double offset, BufferParameters bufferParameters) {
list.add(lineString.getFactory().createLineString(new OffsetCurveBuilder(lineString.getPrecisionModel(), bufferParameters).getOffsetCurve(lineString.getCoordinates(), offset)));
} | java | public static void lineStringOffSetCurve(ArrayList<LineString> list, LineString lineString, double offset, BufferParameters bufferParameters) {
list.add(lineString.getFactory().createLineString(new OffsetCurveBuilder(lineString.getPrecisionModel(), bufferParameters).getOffsetCurve(lineString.getCoordinates(), offset)));
} | [
"public",
"static",
"void",
"lineStringOffSetCurve",
"(",
"ArrayList",
"<",
"LineString",
">",
"list",
",",
"LineString",
"lineString",
",",
"double",
"offset",
",",
"BufferParameters",
"bufferParameters",
")",
"{",
"list",
".",
"add",
"(",
"lineString",
".",
"g... | Compute the offset curve for a linestring
@param list
@param lineString
@param offset
@param bufferParameters | [
"Compute",
"the",
"offset",
"curve",
"for",
"a",
"linestring"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java#L149-L151 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java | ST_OffSetCurve.geometryOffSetCurve | public static void geometryOffSetCurve(ArrayList<LineString> list, Geometry geometry, double offset, BufferParameters bufferParameters) {
final List curves = new OffsetCurveSetBuilder(geometry, offset, new OffsetCurveBuilder(geometry.getFactory().getPrecisionModel(), bufferParameters)).getCurves();
final Iterator<SegmentString> iterator = curves.iterator();
while (iterator.hasNext()) {
list.add(geometry.getFactory().createLineString(iterator.next().getCoordinates()));
}
} | java | public static void geometryOffSetCurve(ArrayList<LineString> list, Geometry geometry, double offset, BufferParameters bufferParameters) {
final List curves = new OffsetCurveSetBuilder(geometry, offset, new OffsetCurveBuilder(geometry.getFactory().getPrecisionModel(), bufferParameters)).getCurves();
final Iterator<SegmentString> iterator = curves.iterator();
while (iterator.hasNext()) {
list.add(geometry.getFactory().createLineString(iterator.next().getCoordinates()));
}
} | [
"public",
"static",
"void",
"geometryOffSetCurve",
"(",
"ArrayList",
"<",
"LineString",
">",
"list",
",",
"Geometry",
"geometry",
",",
"double",
"offset",
",",
"BufferParameters",
"bufferParameters",
")",
"{",
"final",
"List",
"curves",
"=",
"new",
"OffsetCurveSet... | Compute the offset curve for a polygon, a point or a collection of geometries
@param list
@param geometry
@param offset
@param bufferParameters | [
"Compute",
"the",
"offset",
"curve",
"for",
"a",
"polygon",
"a",
"point",
"or",
"a",
"collection",
"of",
"geometries"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_OffSetCurve.java#L160-L166 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/ST_LongestLine.java | ST_LongestLine.longestLine | public static Geometry longestLine(Geometry geomA, Geometry geomB) {
Coordinate[] coords = new MaxDistanceOp(geomA, geomB).getCoordinatesDistance();
if(coords!=null){
return geomA.getFactory().createLineString(coords);
}
return null;
} | java | public static Geometry longestLine(Geometry geomA, Geometry geomB) {
Coordinate[] coords = new MaxDistanceOp(geomA, geomB).getCoordinatesDistance();
if(coords!=null){
return geomA.getFactory().createLineString(coords);
}
return null;
} | [
"public",
"static",
"Geometry",
"longestLine",
"(",
"Geometry",
"geomA",
",",
"Geometry",
"geomB",
")",
"{",
"Coordinate",
"[",
"]",
"coords",
"=",
"new",
"MaxDistanceOp",
"(",
"geomA",
",",
"geomB",
")",
".",
"getCoordinatesDistance",
"(",
")",
";",
"if",
... | Return the longest line between the points of two geometries.
@param geomA
@param geomB
@return | [
"Return",
"the",
"longest",
"line",
"between",
"the",
"points",
"of",
"two",
"geometries",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/ST_LongestLine.java#L50-L56 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_Force2D.java | ST_Force2D.force2D | public static Geometry force2D(Geometry geom) {
if (geom == null) {
return null;
}
return GeometryCoordinateDimension.force(geom, 2);
} | java | public static Geometry force2D(Geometry geom) {
if (geom == null) {
return null;
}
return GeometryCoordinateDimension.force(geom, 2);
} | [
"public",
"static",
"Geometry",
"force2D",
"(",
"Geometry",
"geom",
")",
"{",
"if",
"(",
"geom",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"GeometryCoordinateDimension",
".",
"force",
"(",
"geom",
",",
"2",
")",
";",
"}"
] | Converts a XYZ geometry to XY.
@param geom
@return | [
"Converts",
"a",
"XYZ",
"geometry",
"to",
"XY",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_Force2D.java#L50-L55 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/GeometryMetaData.java | GeometryMetaData.getMetaDataFromWKB | public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException {
ByteOrderDataInStream dis = new ByteOrderDataInStream();
dis.setInStream(new ByteArrayInStream(bytes));
// determine byte order
byte byteOrderWKB = dis.readByte();
// always set byte order, since it may change from geometry to geometry
int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN;
dis.setOrder(byteOrder);
int typeInt = dis.readInt();
int geometryType = typeInt & 0xff;
// determine if Z values are present
boolean hasZ = (typeInt & 0x80000000) != 0;
int inputDimension = hasZ ? 3 : 2;
// determine if SRIDs are present
boolean hasSRID = (typeInt & 0x20000000) != 0;
int SRID = 0;
if (hasSRID) {
SRID = dis.readInt();
}
return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID);
} | java | public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException {
ByteOrderDataInStream dis = new ByteOrderDataInStream();
dis.setInStream(new ByteArrayInStream(bytes));
// determine byte order
byte byteOrderWKB = dis.readByte();
// always set byte order, since it may change from geometry to geometry
int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN;
dis.setOrder(byteOrder);
int typeInt = dis.readInt();
int geometryType = typeInt & 0xff;
// determine if Z values are present
boolean hasZ = (typeInt & 0x80000000) != 0;
int inputDimension = hasZ ? 3 : 2;
// determine if SRIDs are present
boolean hasSRID = (typeInt & 0x20000000) != 0;
int SRID = 0;
if (hasSRID) {
SRID = dis.readInt();
}
return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID);
} | [
"public",
"static",
"GeometryMetaData",
"getMetaDataFromWKB",
"(",
"byte",
"[",
"]",
"bytes",
")",
"throws",
"IOException",
"{",
"ByteOrderDataInStream",
"dis",
"=",
"new",
"ByteOrderDataInStream",
"(",
")",
";",
"dis",
".",
"setInStream",
"(",
"new",
"ByteArrayIn... | Read the first bytes of Geometry WKB.
@param bytes WKB Bytes
@return Geometry MetaData
@throws IOException If WKB meta is invalid (do not check the Geometry) | [
"Read",
"the",
"first",
"bytes",
"of",
"Geometry",
"WKB",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/GeometryMetaData.java#L60-L82 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java | ShapefileWriter.writeHeaders | public void writeHeaders(ShapeType type) throws IOException {
try {
handler = type.getShapeHandler();
} catch (ShapefileException se) {
throw new IOException("Error with type " + type, se);
}
if(indexBuffer != null) {
indexBuffer.flush();
}
if(shapeBuffer != null) {
shapeBuffer.flush();
}
long fileLength = shpChannel.position();
shpChannel.position(0);
shxChannel.position(0);
ShapefileHeader header = new ShapefileHeader();
Envelope writeBounds = bounds;
if(writeBounds == null) {
writeBounds = new Envelope();
}
indexBuffer = new WriteBufferManager(shxChannel);
shapeBuffer = new WriteBufferManager(shpChannel);
header.write(shapeBuffer, type, cnt, (int)(fileLength / 2),
writeBounds.getMinX(), writeBounds.getMinY(), writeBounds.getMaxX(), writeBounds
.getMaxY());
header.write(indexBuffer, type, cnt,
50 + 4 * cnt, writeBounds.getMinX(),
writeBounds.getMinY(), writeBounds.getMaxX(), writeBounds.getMaxY());
offset = 50;
this.type = type;
} | java | public void writeHeaders(ShapeType type) throws IOException {
try {
handler = type.getShapeHandler();
} catch (ShapefileException se) {
throw new IOException("Error with type " + type, se);
}
if(indexBuffer != null) {
indexBuffer.flush();
}
if(shapeBuffer != null) {
shapeBuffer.flush();
}
long fileLength = shpChannel.position();
shpChannel.position(0);
shxChannel.position(0);
ShapefileHeader header = new ShapefileHeader();
Envelope writeBounds = bounds;
if(writeBounds == null) {
writeBounds = new Envelope();
}
indexBuffer = new WriteBufferManager(shxChannel);
shapeBuffer = new WriteBufferManager(shpChannel);
header.write(shapeBuffer, type, cnt, (int)(fileLength / 2),
writeBounds.getMinX(), writeBounds.getMinY(), writeBounds.getMaxX(), writeBounds
.getMaxY());
header.write(indexBuffer, type, cnt,
50 + 4 * cnt, writeBounds.getMinX(),
writeBounds.getMinY(), writeBounds.getMaxX(), writeBounds.getMaxY());
offset = 50;
this.type = type;
} | [
"public",
"void",
"writeHeaders",
"(",
"ShapeType",
"type",
")",
"throws",
"IOException",
"{",
"try",
"{",
"handler",
"=",
"type",
".",
"getShapeHandler",
"(",
")",
";",
"}",
"catch",
"(",
"ShapefileException",
"se",
")",
"{",
"throw",
"new",
"IOException",
... | Write the headers for this shapefile.Use this function before inserting the first geometry, then when all geometries are inserted.
@param type Shape type
@throws java.io.IOException | [
"Write",
"the",
"headers",
"for",
"this",
"shapefile",
".",
"Use",
"this",
"function",
"before",
"inserting",
"the",
"first",
"geometry",
"then",
"when",
"all",
"geometries",
"are",
"inserted",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java#L99-L129 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java | ShapefileWriter.writeGeometry | public void writeGeometry(Geometry g) throws IOException {
if(type == null) {
throw new IllegalStateException("Header must be written before writeGeometry");
}
if(bounds != null) {
if(g != null) {
bounds.expandToInclude(g.getEnvelopeInternal());
}
} else {
bounds = g.getEnvelopeInternal();
}
int length;
if (g == null) {
length = 4;
} else {
length = handler.getLength(g);
}
length /= 2;
shapeBuffer.order(ByteOrder.BIG_ENDIAN);
shapeBuffer.putInt(++cnt);
shapeBuffer.putInt(length);
shapeBuffer.order(ByteOrder.LITTLE_ENDIAN);
if (g == null) {
shapeBuffer.putInt(0);
} else {
shapeBuffer.putInt(type.id);
handler.write(shapeBuffer, g);
}
// write to the shx
indexBuffer.putInt(offset);
indexBuffer.putInt(length);
offset += length + 4;
} | java | public void writeGeometry(Geometry g) throws IOException {
if(type == null) {
throw new IllegalStateException("Header must be written before writeGeometry");
}
if(bounds != null) {
if(g != null) {
bounds.expandToInclude(g.getEnvelopeInternal());
}
} else {
bounds = g.getEnvelopeInternal();
}
int length;
if (g == null) {
length = 4;
} else {
length = handler.getLength(g);
}
length /= 2;
shapeBuffer.order(ByteOrder.BIG_ENDIAN);
shapeBuffer.putInt(++cnt);
shapeBuffer.putInt(length);
shapeBuffer.order(ByteOrder.LITTLE_ENDIAN);
if (g == null) {
shapeBuffer.putInt(0);
} else {
shapeBuffer.putInt(type.id);
handler.write(shapeBuffer, g);
}
// write to the shx
indexBuffer.putInt(offset);
indexBuffer.putInt(length);
offset += length + 4;
} | [
"public",
"void",
"writeGeometry",
"(",
"Geometry",
"g",
")",
"throws",
"IOException",
"{",
"if",
"(",
"type",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Header must be written before writeGeometry\"",
")",
";",
"}",
"if",
"(",
"bou... | Write a single Geometry to this shapefile. The Geometry must be
compatable with the ShapeType assigned during the writing of the headers.
@param g
@throws java.io.IOException | [
"Write",
"a",
"single",
"Geometry",
"to",
"this",
"shapefile",
".",
"The",
"Geometry",
"must",
"be",
"compatable",
"with",
"the",
"ShapeType",
"assigned",
"during",
"the",
"writing",
"of",
"the",
"headers",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java#L138-L173 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java | ShapefileWriter.close | public void close() throws IOException {
indexBuffer.flush();
shapeBuffer.flush();
if (shpChannel != null && shpChannel.isOpen()) {
shpChannel.close();
}
if (shxChannel != null && shxChannel.isOpen()) {
shxChannel.close();
}
shpChannel = null;
shxChannel = null;
handler = null;
indexBuffer = null;
shapeBuffer = null;
} | java | public void close() throws IOException {
indexBuffer.flush();
shapeBuffer.flush();
if (shpChannel != null && shpChannel.isOpen()) {
shpChannel.close();
}
if (shxChannel != null && shxChannel.isOpen()) {
shxChannel.close();
}
shpChannel = null;
shxChannel = null;
handler = null;
indexBuffer = null;
shapeBuffer = null;
} | [
"public",
"void",
"close",
"(",
")",
"throws",
"IOException",
"{",
"indexBuffer",
".",
"flush",
"(",
")",
";",
"shapeBuffer",
".",
"flush",
"(",
")",
";",
"if",
"(",
"shpChannel",
"!=",
"null",
"&&",
"shpChannel",
".",
"isOpen",
"(",
")",
")",
"{",
"... | Close the underlying Channels.
@throws java.io.IOException | [
"Close",
"the",
"underlying",
"Channels",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/ShapefileWriter.java#L180-L194 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java | GraphCreator.prepareGraph | protected KeyedGraph<V, E> prepareGraph() throws SQLException {
LOGGER.info("Loading graph into memory...");
final long start = System.currentTimeMillis();
// Initialize the graph.
KeyedGraph<V, E> graph;
if (!globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
if (weightColumn != null) {
graph = new DirectedWeightedPseudoG<V, E>(vertexClass, edgeClass);
} else {
graph = new DirectedPseudoG<V, E>(vertexClass, edgeClass);
}
} else {
if (weightColumn != null) {
graph = new WeightedPseudoG<V, E>(vertexClass, edgeClass);
} else {
graph = new PseudoG<V, E>(vertexClass, edgeClass);
}
}
final Statement st = connection.createStatement();
final ResultSet edges = st.executeQuery("SELECT * FROM " +
TableUtilities.parseInputTable(connection, inputTable));
// Initialize the indices.
initIndices(edges);
try {
// Add the edges.
while (edges.next()) {
loadEdge(graph, edges);
}
logTime(LOGGER, start);
return graph;
} catch (SQLException e) {
LOGGER.error("Could not store edges in graph.", e);
return null;
} finally {
edges.close();
st.close();
}
} | java | protected KeyedGraph<V, E> prepareGraph() throws SQLException {
LOGGER.info("Loading graph into memory...");
final long start = System.currentTimeMillis();
// Initialize the graph.
KeyedGraph<V, E> graph;
if (!globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
if (weightColumn != null) {
graph = new DirectedWeightedPseudoG<V, E>(vertexClass, edgeClass);
} else {
graph = new DirectedPseudoG<V, E>(vertexClass, edgeClass);
}
} else {
if (weightColumn != null) {
graph = new WeightedPseudoG<V, E>(vertexClass, edgeClass);
} else {
graph = new PseudoG<V, E>(vertexClass, edgeClass);
}
}
final Statement st = connection.createStatement();
final ResultSet edges = st.executeQuery("SELECT * FROM " +
TableUtilities.parseInputTable(connection, inputTable));
// Initialize the indices.
initIndices(edges);
try {
// Add the edges.
while (edges.next()) {
loadEdge(graph, edges);
}
logTime(LOGGER, start);
return graph;
} catch (SQLException e) {
LOGGER.error("Could not store edges in graph.", e);
return null;
} finally {
edges.close();
st.close();
}
} | [
"protected",
"KeyedGraph",
"<",
"V",
",",
"E",
">",
"prepareGraph",
"(",
")",
"throws",
"SQLException",
"{",
"LOGGER",
".",
"info",
"(",
"\"Loading graph into memory...\"",
")",
";",
"final",
"long",
"start",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
... | Prepares a graph.
@return The newly prepared graph, or null if the graph could not
be created
@throws java.sql.SQLException | [
"Prepares",
"a",
"graph",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java#L103-L140 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java | GraphCreator.initIndices | private void initIndices(ResultSet edges) {
try {
ResultSetMetaData metaData = edges.getMetaData();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
final String columnName = metaData.getColumnName(i);
if (columnName.equalsIgnoreCase(START_NODE)) startNodeIndex = i;
if (columnName.equalsIgnoreCase(END_NODE)) endNodeIndex = i;
if (columnName.equalsIgnoreCase(EDGE_ID)) edgeIDIndex = i;
if (columnName.equalsIgnoreCase(edgeOrientationColumnName)) edgeOrientationIndex = i;
if (columnName.equalsIgnoreCase(weightColumn)) weightColumnIndex = i;
}
} catch (SQLException e) {
LOGGER.error("Problem accessing edge table metadata.", e);
}
verifyIndex(startNodeIndex, START_NODE);
verifyIndex(endNodeIndex, END_NODE);
verifyIndex(edgeIDIndex, EDGE_ID);
if (!globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
verifyIndex(edgeOrientationIndex, edgeOrientationColumnName);
}
if (weightColumn != null) {
verifyIndex(weightColumnIndex, weightColumn);
}
} | java | private void initIndices(ResultSet edges) {
try {
ResultSetMetaData metaData = edges.getMetaData();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
final String columnName = metaData.getColumnName(i);
if (columnName.equalsIgnoreCase(START_NODE)) startNodeIndex = i;
if (columnName.equalsIgnoreCase(END_NODE)) endNodeIndex = i;
if (columnName.equalsIgnoreCase(EDGE_ID)) edgeIDIndex = i;
if (columnName.equalsIgnoreCase(edgeOrientationColumnName)) edgeOrientationIndex = i;
if (columnName.equalsIgnoreCase(weightColumn)) weightColumnIndex = i;
}
} catch (SQLException e) {
LOGGER.error("Problem accessing edge table metadata.", e);
}
verifyIndex(startNodeIndex, START_NODE);
verifyIndex(endNodeIndex, END_NODE);
verifyIndex(edgeIDIndex, EDGE_ID);
if (!globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
verifyIndex(edgeOrientationIndex, edgeOrientationColumnName);
}
if (weightColumn != null) {
verifyIndex(weightColumnIndex, weightColumn);
}
} | [
"private",
"void",
"initIndices",
"(",
"ResultSet",
"edges",
")",
"{",
"try",
"{",
"ResultSetMetaData",
"metaData",
"=",
"edges",
".",
"getMetaData",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"metaData",
".",
"getColumnCount",
"(",... | Recovers the indices from the metadata. | [
"Recovers",
"the",
"indices",
"from",
"the",
"metadata",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java#L145-L168 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java | GraphCreator.loadEdge | private E loadEdge(KeyedGraph<V, E> graph, ResultSet edges) throws SQLException {
final int startNode = edges.getInt(startNodeIndex);
final int endNode = edges.getInt(endNodeIndex);
final int edgeID = edges.getInt(edgeIDIndex);
double weight = WeightedGraph.DEFAULT_EDGE_WEIGHT;
if (weightColumnIndex != -1) {
weight = edges.getDouble(weightColumnIndex);
}
E edge;
// Undirected graphs are either pseudographs or weighted pseudographs,
// so there is no need to add edges in both directions.
if (globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
edge = graph.addEdge(endNode, startNode, edgeID);
} else {
// Directed graphs are either directed pseudographs or directed
// weighted pseudographs and must specify an orientation for each
// individual edge. If no orientations are specified, every edge
// is considered to be directed with orientation given by the
// geometry.
int edgeOrientation = (edgeOrientationIndex == -1)
? DIRECTED_EDGE
: edges.getInt(edgeOrientationIndex);
if (edges.wasNull()) {
throw new IllegalArgumentException("Invalid edge orientation: NULL.");
}
if (edgeOrientation == UNDIRECTED_EDGE) {
if (globalOrientation.equals(GraphFunctionParser.Orientation.DIRECTED)) {
edge = loadDoubleEdge(graph, startNode, endNode, edgeID, weight);
} // globalOrientation == Orientation.REVERSED
else {
edge = loadDoubleEdge(graph, endNode, startNode, edgeID, weight);
}
} else if (edgeOrientation == DIRECTED_EDGE) {
// Reverse a directed edge (global).
if (globalOrientation.equals(GraphFunctionParser.Orientation.REVERSED)) {
edge = graph.addEdge(endNode, startNode, edgeID);
} // No reversal.
else {
edge = graph.addEdge(startNode, endNode, edgeID);
}
} else if (edgeOrientation == REVERSED_EDGE) {
// Reversing twice is the same as no reversal.
if (globalOrientation.equals(GraphFunctionParser.Orientation.REVERSED)) {
edge = graph.addEdge(startNode, endNode, edgeID);
} // Otherwise reverse just once (local).
else {
edge = graph.addEdge(endNode, startNode, edgeID);
}
} else {
throw new IllegalArgumentException("Invalid edge orientation: " + edgeOrientation);
}
}
setEdgeWeight(edge, weight);
return edge;
} | java | private E loadEdge(KeyedGraph<V, E> graph, ResultSet edges) throws SQLException {
final int startNode = edges.getInt(startNodeIndex);
final int endNode = edges.getInt(endNodeIndex);
final int edgeID = edges.getInt(edgeIDIndex);
double weight = WeightedGraph.DEFAULT_EDGE_WEIGHT;
if (weightColumnIndex != -1) {
weight = edges.getDouble(weightColumnIndex);
}
E edge;
// Undirected graphs are either pseudographs or weighted pseudographs,
// so there is no need to add edges in both directions.
if (globalOrientation.equals(GraphFunctionParser.Orientation.UNDIRECTED)) {
edge = graph.addEdge(endNode, startNode, edgeID);
} else {
// Directed graphs are either directed pseudographs or directed
// weighted pseudographs and must specify an orientation for each
// individual edge. If no orientations are specified, every edge
// is considered to be directed with orientation given by the
// geometry.
int edgeOrientation = (edgeOrientationIndex == -1)
? DIRECTED_EDGE
: edges.getInt(edgeOrientationIndex);
if (edges.wasNull()) {
throw new IllegalArgumentException("Invalid edge orientation: NULL.");
}
if (edgeOrientation == UNDIRECTED_EDGE) {
if (globalOrientation.equals(GraphFunctionParser.Orientation.DIRECTED)) {
edge = loadDoubleEdge(graph, startNode, endNode, edgeID, weight);
} // globalOrientation == Orientation.REVERSED
else {
edge = loadDoubleEdge(graph, endNode, startNode, edgeID, weight);
}
} else if (edgeOrientation == DIRECTED_EDGE) {
// Reverse a directed edge (global).
if (globalOrientation.equals(GraphFunctionParser.Orientation.REVERSED)) {
edge = graph.addEdge(endNode, startNode, edgeID);
} // No reversal.
else {
edge = graph.addEdge(startNode, endNode, edgeID);
}
} else if (edgeOrientation == REVERSED_EDGE) {
// Reversing twice is the same as no reversal.
if (globalOrientation.equals(GraphFunctionParser.Orientation.REVERSED)) {
edge = graph.addEdge(startNode, endNode, edgeID);
} // Otherwise reverse just once (local).
else {
edge = graph.addEdge(endNode, startNode, edgeID);
}
} else {
throw new IllegalArgumentException("Invalid edge orientation: " + edgeOrientation);
}
}
setEdgeWeight(edge, weight);
return edge;
} | [
"private",
"E",
"loadEdge",
"(",
"KeyedGraph",
"<",
"V",
",",
"E",
">",
"graph",
",",
"ResultSet",
"edges",
")",
"throws",
"SQLException",
"{",
"final",
"int",
"startNode",
"=",
"edges",
".",
"getInt",
"(",
"startNodeIndex",
")",
";",
"final",
"int",
"en... | Loads an edge into the graph from the current row.
@param graph The graph to which the edges will be added.
@return The newly loaded edge. | [
"Loads",
"an",
"edge",
"into",
"the",
"graph",
"from",
"the",
"current",
"row",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java#L190-L244 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java | GraphCreator.loadDoubleEdge | private E loadDoubleEdge(KeyedGraph<V, E> graph,
final int startNode,
final int endNode,
final int edgeID,
final double weight) throws SQLException {
// Note: row is ignored since we only need it for weighted graphs.
final E edgeTo = graph.addEdge(startNode, endNode, edgeID);
setEdgeWeight(edgeTo, weight);
final E edgeFrom = graph.addEdge(endNode, startNode, -edgeID);
setEdgeWeight(edgeFrom, weight);
return edgeFrom;
} | java | private E loadDoubleEdge(KeyedGraph<V, E> graph,
final int startNode,
final int endNode,
final int edgeID,
final double weight) throws SQLException {
// Note: row is ignored since we only need it for weighted graphs.
final E edgeTo = graph.addEdge(startNode, endNode, edgeID);
setEdgeWeight(edgeTo, weight);
final E edgeFrom = graph.addEdge(endNode, startNode, -edgeID);
setEdgeWeight(edgeFrom, weight);
return edgeFrom;
} | [
"private",
"E",
"loadDoubleEdge",
"(",
"KeyedGraph",
"<",
"V",
",",
"E",
">",
"graph",
",",
"final",
"int",
"startNode",
",",
"final",
"int",
"endNode",
",",
"final",
"int",
"edgeID",
",",
"final",
"double",
"weight",
")",
"throws",
"SQLException",
"{",
... | In directed graphs, undirected edges are represented by directed edges
in both directions. The edges are assigned ids with opposite signs.
@param graph The graph to which the edges will be added.
@param startNode Start node id
@param endNode End Node id
@param edgeID Edge id
@return One of the two directed edges used to represent an undirected
edge in a directed graph (the one with a negative id). | [
"In",
"directed",
"graphs",
"undirected",
"edges",
"are",
"represented",
"by",
"directed",
"edges",
"in",
"both",
"directions",
".",
"The",
"edges",
"are",
"assigned",
"ids",
"with",
"opposite",
"signs",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java#L258-L270 | train |
orbisgis/h2gis | h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java | GraphCreator.setEdgeWeight | private void setEdgeWeight(E edge, final double weight) throws SQLException {
if (edge != null && weightColumnIndex != -1) {
edge.setWeight(weight);
}
} | java | private void setEdgeWeight(E edge, final double weight) throws SQLException {
if (edge != null && weightColumnIndex != -1) {
edge.setWeight(weight);
}
} | [
"private",
"void",
"setEdgeWeight",
"(",
"E",
"edge",
",",
"final",
"double",
"weight",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"edge",
"!=",
"null",
"&&",
"weightColumnIndex",
"!=",
"-",
"1",
")",
"{",
"edge",
".",
"setWeight",
"(",
"weight",
")"... | Set this edge's weight to the weight contained in the current row.
@param edge Edge
@throws SQLException If the weight cannot be retrieved | [
"Set",
"this",
"edge",
"s",
"weight",
"to",
"the",
"weight",
"contained",
"in",
"the",
"current",
"row",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-network/src/main/java/org/h2gis/network/functions/GraphCreator.java#L278-L282 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_GeometryN.java | ST_GeometryN.getGeometryN | public static Geometry getGeometryN(Geometry geometry, Integer n) throws SQLException {
if (geometry == null) {
return null;
}
if (n >= 1 && n <= geometry.getNumGeometries()) {
return geometry.getGeometryN(n - 1);
} else {
throw new SQLException(OUT_OF_BOUNDS_ERR_MESSAGE);
}
} | java | public static Geometry getGeometryN(Geometry geometry, Integer n) throws SQLException {
if (geometry == null) {
return null;
}
if (n >= 1 && n <= geometry.getNumGeometries()) {
return geometry.getGeometryN(n - 1);
} else {
throw new SQLException(OUT_OF_BOUNDS_ERR_MESSAGE);
}
} | [
"public",
"static",
"Geometry",
"getGeometryN",
"(",
"Geometry",
"geometry",
",",
"Integer",
"n",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"n",
">=",
"1",
"&&",
"n",
"<=",... | Return Geometry number n from the given GeometryCollection.
@param geometry GeometryCollection
@param n Index of Geometry number n in [1-N]
@return Geometry number n or Null if parameter is null.
@throws SQLException | [
"Return",
"Geometry",
"number",
"n",
"from",
"the",
"given",
"GeometryCollection",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_GeometryN.java#L61-L70 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_Holes.java | ST_Holes.getHoles | public static GeometryCollection getHoles(Geometry geom) throws SQLException {
if (geom != null) {
if (geom.getDimension() >= 2) {
ArrayList<Geometry> holes = new ArrayList<Geometry>();
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subgeom = geom.getGeometryN(i);
if (subgeom instanceof Polygon) {
Polygon polygon = (Polygon) subgeom;
for (int j = 0; j < polygon.getNumInteriorRing(); j++) {
holes.add(GEOMETRY_FACTORY.createPolygon(
GEOMETRY_FACTORY.createLinearRing(
polygon.getInteriorRingN(j).getCoordinates()), null));
}
}
}
return GEOMETRY_FACTORY.createGeometryCollection(
holes.toArray(new Geometry[0]));
} else {
return GEOMETRY_FACTORY.createGeometryCollection(null);
}
}
return null;
} | java | public static GeometryCollection getHoles(Geometry geom) throws SQLException {
if (geom != null) {
if (geom.getDimension() >= 2) {
ArrayList<Geometry> holes = new ArrayList<Geometry>();
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subgeom = geom.getGeometryN(i);
if (subgeom instanceof Polygon) {
Polygon polygon = (Polygon) subgeom;
for (int j = 0; j < polygon.getNumInteriorRing(); j++) {
holes.add(GEOMETRY_FACTORY.createPolygon(
GEOMETRY_FACTORY.createLinearRing(
polygon.getInteriorRingN(j).getCoordinates()), null));
}
}
}
return GEOMETRY_FACTORY.createGeometryCollection(
holes.toArray(new Geometry[0]));
} else {
return GEOMETRY_FACTORY.createGeometryCollection(null);
}
}
return null;
} | [
"public",
"static",
"GeometryCollection",
"getHoles",
"(",
"Geometry",
"geom",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geom",
"!=",
"null",
")",
"{",
"if",
"(",
"geom",
".",
"getDimension",
"(",
")",
">=",
"2",
")",
"{",
"ArrayList",
"<",
"Geomet... | Returns the given geometry's holes as a GeometryCollection.
@param geom Geometry
@return The geometry's holes
@throws SQLException | [
"Returns",
"the",
"given",
"geometry",
"s",
"holes",
"as",
"a",
"GeometryCollection",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_Holes.java#L61-L83 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/MultiPointHandler.java | MultiPointHandler.getLength | @Override
public int getLength(Object geometry) {
MultiPoint mp = (MultiPoint) geometry;
int length;
if (shapeType == ShapeType.MULTIPOINT) {
// two doubles per coord (16 * numgeoms) + 40 for header
length = (mp.getNumGeometries() * 16) + 40;
} else if (shapeType == ShapeType.MULTIPOINTM) {
// add the additional MMin, MMax for 16, then 8 per measure
length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries());
} else if (shapeType == ShapeType.MULTIPOINTZ) {
// add the additional ZMin,ZMax, plus 8 per Z
length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries()) + 16
+ (8 * mp.getNumGeometries());
} else {
throw new IllegalStateException("Expected ShapeType of Arc, got " + shapeType);
}
return length;
} | java | @Override
public int getLength(Object geometry) {
MultiPoint mp = (MultiPoint) geometry;
int length;
if (shapeType == ShapeType.MULTIPOINT) {
// two doubles per coord (16 * numgeoms) + 40 for header
length = (mp.getNumGeometries() * 16) + 40;
} else if (shapeType == ShapeType.MULTIPOINTM) {
// add the additional MMin, MMax for 16, then 8 per measure
length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries());
} else if (shapeType == ShapeType.MULTIPOINTZ) {
// add the additional ZMin,ZMax, plus 8 per Z
length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries()) + 16
+ (8 * mp.getNumGeometries());
} else {
throw new IllegalStateException("Expected ShapeType of Arc, got " + shapeType);
}
return length;
} | [
"@",
"Override",
"public",
"int",
"getLength",
"(",
"Object",
"geometry",
")",
"{",
"MultiPoint",
"mp",
"=",
"(",
"MultiPoint",
")",
"geometry",
";",
"int",
"length",
";",
"if",
"(",
"shapeType",
"==",
"ShapeType",
".",
"MULTIPOINT",
")",
"{",
"// two doub... | Calcuates the record length of this object.
@return int The length of the record that this shapepoint will take up in a shapefile | [
"Calcuates",
"the",
"record",
"length",
"of",
"this",
"object",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/MultiPointHandler.java#L69-L90 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/SpatialRefRegistry.java | SpatialRefRegistry.formatKey | private static String formatKey(String prjKey) {
String formatKey = prjKey;
if (prjKey.startsWith("+")) {
formatKey = prjKey.substring(1);
}
return formatKey;
} | java | private static String formatKey(String prjKey) {
String formatKey = prjKey;
if (prjKey.startsWith("+")) {
formatKey = prjKey.substring(1);
}
return formatKey;
} | [
"private",
"static",
"String",
"formatKey",
"(",
"String",
"prjKey",
")",
"{",
"String",
"formatKey",
"=",
"prjKey",
";",
"if",
"(",
"prjKey",
".",
"startsWith",
"(",
"\"+\"",
")",
")",
"{",
"formatKey",
"=",
"prjKey",
".",
"substring",
"(",
"1",
")",
... | Remove + char if exists
@param prjKey represents a proj key parameter
@return a new string without + char | [
"Remove",
"+",
"char",
"if",
"exists"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/SpatialRefRegistry.java#L97-L103 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java | PRJUtil.getSRID | public static int getSRID(File prjFile) throws IOException {
int srid = 0;
if (prjFile == null) {
log.debug("This prj file is null. \n A default srid equals to 0 will be added.");
} else {
PrjParser parser = new PrjParser();
String prjString = readPRJFile(prjFile);
if (!prjString.isEmpty()) {
Map<String, String> p = parser.getParameters(prjString);
String authorityWithCode = p.get(PrjKeyParameters.REFNAME);
if (authorityWithCode != null) {
String[] authorityNameWithKey = authorityWithCode.split(":");
srid = Integer.valueOf(authorityNameWithKey[1]);
}
}
else{
log.debug("The prj is empty. \n A default srid equals to 0 will be added.");
}
}
return srid;
} | java | public static int getSRID(File prjFile) throws IOException {
int srid = 0;
if (prjFile == null) {
log.debug("This prj file is null. \n A default srid equals to 0 will be added.");
} else {
PrjParser parser = new PrjParser();
String prjString = readPRJFile(prjFile);
if (!prjString.isEmpty()) {
Map<String, String> p = parser.getParameters(prjString);
String authorityWithCode = p.get(PrjKeyParameters.REFNAME);
if (authorityWithCode != null) {
String[] authorityNameWithKey = authorityWithCode.split(":");
srid = Integer.valueOf(authorityNameWithKey[1]);
}
}
else{
log.debug("The prj is empty. \n A default srid equals to 0 will be added.");
}
}
return srid;
} | [
"public",
"static",
"int",
"getSRID",
"(",
"File",
"prjFile",
")",
"throws",
"IOException",
"{",
"int",
"srid",
"=",
"0",
";",
"if",
"(",
"prjFile",
"==",
"null",
")",
"{",
"log",
".",
"debug",
"(",
"\"This prj file is null. \\n A default srid equals to 0 will b... | Return the SRID value stored in a prj file
If the the prj file
- is null,
- is empty
then a default srid equals to 0 is added.
@param prjFile
@return
@throws IOException | [
"Return",
"the",
"SRID",
"value",
"stored",
"in",
"a",
"prj",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java#L59-L79 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java | PRJUtil.readPRJFile | private static String readPRJFile(File prjFile) throws FileNotFoundException, IOException {
try (FileInputStream fis = new FileInputStream(prjFile)) {
BufferedReader r = new BufferedReader(new InputStreamReader(fis, Charset.defaultCharset()));
StringBuilder b = new StringBuilder();
while (r.ready()) {
b.append(r.readLine());
}
return b.toString();
}
} | java | private static String readPRJFile(File prjFile) throws FileNotFoundException, IOException {
try (FileInputStream fis = new FileInputStream(prjFile)) {
BufferedReader r = new BufferedReader(new InputStreamReader(fis, Charset.defaultCharset()));
StringBuilder b = new StringBuilder();
while (r.ready()) {
b.append(r.readLine());
}
return b.toString();
}
} | [
"private",
"static",
"String",
"readPRJFile",
"(",
"File",
"prjFile",
")",
"throws",
"FileNotFoundException",
",",
"IOException",
"{",
"try",
"(",
"FileInputStream",
"fis",
"=",
"new",
"FileInputStream",
"(",
"prjFile",
")",
")",
"{",
"BufferedReader",
"r",
"=",... | Return the content of the PRJ file as a single string
@param prjFile
@return
@throws FileNotFoundException
@throws IOException | [
"Return",
"the",
"content",
"of",
"the",
"PRJ",
"file",
"as",
"a",
"single",
"string"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java#L111-L120 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java | PRJUtil.writePRJ | public static void writePRJ(Connection connection, TableLocation location, String geomField, File fileName) throws SQLException, FileNotFoundException {
int srid = SFSUtilities.getSRID(connection, location, geomField);
writePRJ(connection, srid, fileName);
} | java | public static void writePRJ(Connection connection, TableLocation location, String geomField, File fileName) throws SQLException, FileNotFoundException {
int srid = SFSUtilities.getSRID(connection, location, geomField);
writePRJ(connection, srid, fileName);
} | [
"public",
"static",
"void",
"writePRJ",
"(",
"Connection",
"connection",
",",
"TableLocation",
"location",
",",
"String",
"geomField",
",",
"File",
"fileName",
")",
"throws",
"SQLException",
",",
"FileNotFoundException",
"{",
"int",
"srid",
"=",
"SFSUtilities",
".... | Write a prj file according the SRID code of an input table
@param connection database connection
@param location input table name
@param geomField geometry field name
@param fileName path of the prj file
@throws SQLException
@throws FileNotFoundException | [
"Write",
"a",
"prj",
"file",
"according",
"the",
"SRID",
"code",
"of",
"an",
"input",
"table"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java#L132-L135 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java | PRJUtil.writePRJ | public static void writePRJ(Connection connection, int srid, File fileName) throws SQLException, FileNotFoundException {
if (srid != 0) {
StringBuilder sb = new StringBuilder("SELECT SRTEXT FROM ");
sb.append("PUBLIC.SPATIAL_REF_SYS ").append(" WHERE SRID = ?");
PreparedStatement ps = connection.prepareStatement(sb.toString());
ps.setInt(1, srid);
PrintWriter printWriter = null;
ResultSet rs = null;
try {
rs = ps.executeQuery();
if (rs.next()) {
printWriter = new PrintWriter(fileName);
printWriter.println(rs.getString(1));
} else {
log.warn("This SRID { "+ srid +" } is not supported. \n The PRJ file won't be created.");
}
} finally {
if (printWriter != null) {
printWriter.close();
}
if (rs != null) {
rs.close();
}
ps.close();
}
}
} | java | public static void writePRJ(Connection connection, int srid, File fileName) throws SQLException, FileNotFoundException {
if (srid != 0) {
StringBuilder sb = new StringBuilder("SELECT SRTEXT FROM ");
sb.append("PUBLIC.SPATIAL_REF_SYS ").append(" WHERE SRID = ?");
PreparedStatement ps = connection.prepareStatement(sb.toString());
ps.setInt(1, srid);
PrintWriter printWriter = null;
ResultSet rs = null;
try {
rs = ps.executeQuery();
if (rs.next()) {
printWriter = new PrintWriter(fileName);
printWriter.println(rs.getString(1));
} else {
log.warn("This SRID { "+ srid +" } is not supported. \n The PRJ file won't be created.");
}
} finally {
if (printWriter != null) {
printWriter.close();
}
if (rs != null) {
rs.close();
}
ps.close();
}
}
} | [
"public",
"static",
"void",
"writePRJ",
"(",
"Connection",
"connection",
",",
"int",
"srid",
",",
"File",
"fileName",
")",
"throws",
"SQLException",
",",
"FileNotFoundException",
"{",
"if",
"(",
"srid",
"!=",
"0",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",... | Write a prj file according a given SRID code.
@param connection database connection
@param srid srid code
@param fileName path of the prj file
@throws SQLException
@throws FileNotFoundException | [
"Write",
"a",
"prj",
"file",
"according",
"a",
"given",
"SRID",
"code",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java#L146-L172 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java | PRJUtil.isSRIDValid | public static boolean isSRIDValid(int srid, Connection connection) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
String queryCheck = "SELECT count(SRID) from PUBLIC.SPATIAL_REF_SYS WHERE SRID = ?";
try {
ps = connection.prepareStatement(queryCheck);
ps.setInt(1, srid);
rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt(1) != 0;
}
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
}
return false;
} | java | public static boolean isSRIDValid(int srid, Connection connection) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
String queryCheck = "SELECT count(SRID) from PUBLIC.SPATIAL_REF_SYS WHERE SRID = ?";
try {
ps = connection.prepareStatement(queryCheck);
ps.setInt(1, srid);
rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt(1) != 0;
}
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
}
return false;
} | [
"public",
"static",
"boolean",
"isSRIDValid",
"(",
"int",
"srid",
",",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"PreparedStatement",
"ps",
"=",
"null",
";",
"ResultSet",
"rs",
"=",
"null",
";",
"String",
"queryCheck",
"=",
"\"SELECT count(... | This method checks if a SRID value is valid according a list of SRID's
avalaible on spatial_ref table of the datababase.
@param srid
@param connection
@return
@throws java.sql.SQLException | [
"This",
"method",
"checks",
"if",
"a",
"SRID",
"value",
"is",
"valid",
"according",
"a",
"list",
"of",
"SRID",
"s",
"avalaible",
"on",
"spatial_ref",
"table",
"of",
"the",
"datababase",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/PRJUtil.java#L184-L204 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/FileUtil.java | FileUtil.isFileImportable | public static boolean isFileImportable(File file, String prefix) throws SQLException, FileNotFoundException{
if (isExtensionWellFormated(file, prefix)) {
if (file.exists()) {
return true;
} else {
throw new FileNotFoundException("The following file does not exists:\n" + file.getPath());
}
} else {
throw new SQLException("Please use " + prefix + " extension.");
}
} | java | public static boolean isFileImportable(File file, String prefix) throws SQLException, FileNotFoundException{
if (isExtensionWellFormated(file, prefix)) {
if (file.exists()) {
return true;
} else {
throw new FileNotFoundException("The following file does not exists:\n" + file.getPath());
}
} else {
throw new SQLException("Please use " + prefix + " extension.");
}
} | [
"public",
"static",
"boolean",
"isFileImportable",
"(",
"File",
"file",
",",
"String",
"prefix",
")",
"throws",
"SQLException",
",",
"FileNotFoundException",
"{",
"if",
"(",
"isExtensionWellFormated",
"(",
"file",
",",
"prefix",
")",
")",
"{",
"if",
"(",
"file... | Check if the file is well formatted regarding an extension prefix.
Check also if the file doesn't exist.
@param file
@param prefix
@return
@throws SQLException
@throws java.io.FileNotFoundException | [
"Check",
"if",
"the",
"file",
"is",
"well",
"formatted",
"regarding",
"an",
"extension",
"prefix",
".",
"Check",
"also",
"if",
"the",
"file",
"doesn",
"t",
"exist",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/FileUtil.java#L44-L54 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/FileUtil.java | FileUtil.isExtensionWellFormated | public static boolean isExtensionWellFormated(File file, String prefix) {
String path = file.getAbsolutePath();
String extension = "";
int i = path.lastIndexOf('.');
if (i >= 0) {
extension = path.substring(i + 1);
}
return extension.equalsIgnoreCase(prefix);
} | java | public static boolean isExtensionWellFormated(File file, String prefix) {
String path = file.getAbsolutePath();
String extension = "";
int i = path.lastIndexOf('.');
if (i >= 0) {
extension = path.substring(i + 1);
}
return extension.equalsIgnoreCase(prefix);
} | [
"public",
"static",
"boolean",
"isExtensionWellFormated",
"(",
"File",
"file",
",",
"String",
"prefix",
")",
"{",
"String",
"path",
"=",
"file",
".",
"getAbsolutePath",
"(",
")",
";",
"String",
"extension",
"=",
"\"\"",
";",
"int",
"i",
"=",
"path",
".",
... | Check if the file has the good extension
@param file
@param prefix
@return | [
"Check",
"if",
"the",
"file",
"has",
"the",
"good",
"extension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/FileUtil.java#L62-L70 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/file_table/FileEngine.java | FileEngine.getUniqueColumnName | public static String getUniqueColumnName(String base, List<Column> columns) {
String cursor = base;
int cpt = 2;
boolean findDuplicate= true;
while(findDuplicate) {
findDuplicate = false;
for (Column column : columns) {
if (column.getName().equalsIgnoreCase(cursor)) {
findDuplicate = true;
break;
}
}
if(findDuplicate) {
cursor = base + Integer.toString(cpt);
}
}
return cursor;
} | java | public static String getUniqueColumnName(String base, List<Column> columns) {
String cursor = base;
int cpt = 2;
boolean findDuplicate= true;
while(findDuplicate) {
findDuplicate = false;
for (Column column : columns) {
if (column.getName().equalsIgnoreCase(cursor)) {
findDuplicate = true;
break;
}
}
if(findDuplicate) {
cursor = base + Integer.toString(cpt);
}
}
return cursor;
} | [
"public",
"static",
"String",
"getUniqueColumnName",
"(",
"String",
"base",
",",
"List",
"<",
"Column",
">",
"columns",
")",
"{",
"String",
"cursor",
"=",
"base",
";",
"int",
"cpt",
"=",
"2",
";",
"boolean",
"findDuplicate",
"=",
"true",
";",
"while",
"(... | Compute unique column name among the other columns
@param base Returned name if there is no duplicate
@param columns Other existing columns
@return Unique column name | [
"Compute",
"unique",
"column",
"name",
"among",
"the",
"other",
"columns"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/file_table/FileEngine.java#L84-L101 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/snap/ST_Snap.java | ST_Snap.snap | public static Geometry snap(Geometry geometryA, Geometry geometryB, double distance) {
if(geometryA == null||geometryB == null){
return null;
}
Geometry[] snapped = GeometrySnapper.snap(geometryA, geometryB, distance);
return snapped[0];
} | java | public static Geometry snap(Geometry geometryA, Geometry geometryB, double distance) {
if(geometryA == null||geometryB == null){
return null;
}
Geometry[] snapped = GeometrySnapper.snap(geometryA, geometryB, distance);
return snapped[0];
} | [
"public",
"static",
"Geometry",
"snap",
"(",
"Geometry",
"geometryA",
",",
"Geometry",
"geometryB",
",",
"double",
"distance",
")",
"{",
"if",
"(",
"geometryA",
"==",
"null",
"||",
"geometryB",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Geometry"... | Snaps two geometries together with a given tolerance
@param geometryA a geometry to snap
@param geometryB a geometry to snap
@param distance the tolerance to use
@return the snapped geometries | [
"Snaps",
"two",
"geometries",
"together",
"with",
"a",
"given",
"tolerance"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/snap/ST_Snap.java#L51-L57 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_UpdateZ.java | ST_UpdateZ.updateZ | public static Geometry updateZ(Geometry geometry, double z, int updateCondition) throws SQLException {
if(geometry == null){
return null;
}
if (updateCondition == 1 || updateCondition == 2 || updateCondition == 3) {
Geometry outPut = geometry.copy();
outPut.apply(new UpdateZCoordinateSequenceFilter(z, updateCondition));
return outPut;
} else {
throw new SQLException("Available values are 1, 2 or 3.\n"
+ "Please read the description of the function to use it.");
}
} | java | public static Geometry updateZ(Geometry geometry, double z, int updateCondition) throws SQLException {
if(geometry == null){
return null;
}
if (updateCondition == 1 || updateCondition == 2 || updateCondition == 3) {
Geometry outPut = geometry.copy();
outPut.apply(new UpdateZCoordinateSequenceFilter(z, updateCondition));
return outPut;
} else {
throw new SQLException("Available values are 1, 2 or 3.\n"
+ "Please read the description of the function to use it.");
}
} | [
"public",
"static",
"Geometry",
"updateZ",
"(",
"Geometry",
"geometry",
",",
"double",
"z",
",",
"int",
"updateCondition",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"updateCond... | Replace the z value depending on the condition.
@param geometry
@param z
@param updateCondition set if the NaN value must be updated or not
@return
@throws java.sql.SQLException | [
"Replace",
"the",
"z",
"value",
"depending",
"on",
"the",
"condition",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_UpdateZ.java#L74-L86 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/gpx/model/GpxPreparser.java | GpxPreparser.read | public boolean read(File inputFile) throws SAXException, IOException {
boolean success = false;
try (FileInputStream fs = new FileInputStream(inputFile)) {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setErrorHandler(this);
parser.setContentHandler(this);
parser.parse(new InputSource(fs));
success = true;
}
return success;
} | java | public boolean read(File inputFile) throws SAXException, IOException {
boolean success = false;
try (FileInputStream fs = new FileInputStream(inputFile)) {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setErrorHandler(this);
parser.setContentHandler(this);
parser.parse(new InputSource(fs));
success = true;
}
return success;
} | [
"public",
"boolean",
"read",
"(",
"File",
"inputFile",
")",
"throws",
"SAXException",
",",
"IOException",
"{",
"boolean",
"success",
"=",
"false",
";",
"try",
"(",
"FileInputStream",
"fs",
"=",
"new",
"FileInputStream",
"(",
"inputFile",
")",
")",
"{",
"XMLR... | Reads the document and pre-parses it. The other method is called
automatically when a start markup is found.
@param inputFile the file to read
@return a boolean if the parser ends successfully or not
@throws SAXException
@throws IOException | [
"Reads",
"the",
"document",
"and",
"pre",
"-",
"parses",
"it",
".",
"The",
"other",
"method",
"is",
"called",
"automatically",
"when",
"a",
"start",
"markup",
"is",
"found",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/gpx/model/GpxPreparser.java#L75-L85 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/gpx/model/GpxPreparser.java | GpxPreparser.startElement | @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (localName.compareToIgnoreCase(GPXTags.GPX) == 0) {
version = attributes.getValue(GPXTags.VERSION);
} else if (localName.compareToIgnoreCase(GPXTags.RTE) == 0) {
totalRte++;
} else if (localName.compareToIgnoreCase(GPXTags.TRK) == 0) {
totalTrk++;
} else if (localName.compareToIgnoreCase(GPXTags.TRKSEG) == 0) {
totalTrkseg++;
} else if (localName.compareToIgnoreCase(GPXTags.WPT) == 0) {
totalWpt++;
} else if (localName.compareToIgnoreCase(GPXTags.RTEPT) == 0) {
totalRtept++;
} else if (localName.compareToIgnoreCase(GPXTags.TRKPT) == 0) {
totalTrkpt++;
}
} | java | @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (localName.compareToIgnoreCase(GPXTags.GPX) == 0) {
version = attributes.getValue(GPXTags.VERSION);
} else if (localName.compareToIgnoreCase(GPXTags.RTE) == 0) {
totalRte++;
} else if (localName.compareToIgnoreCase(GPXTags.TRK) == 0) {
totalTrk++;
} else if (localName.compareToIgnoreCase(GPXTags.TRKSEG) == 0) {
totalTrkseg++;
} else if (localName.compareToIgnoreCase(GPXTags.WPT) == 0) {
totalWpt++;
} else if (localName.compareToIgnoreCase(GPXTags.RTEPT) == 0) {
totalRtept++;
} else if (localName.compareToIgnoreCase(GPXTags.TRKPT) == 0) {
totalTrkpt++;
}
} | [
"@",
"Override",
"public",
"void",
"startElement",
"(",
"String",
"uri",
",",
"String",
"localName",
",",
"String",
"qName",
",",
"Attributes",
"attributes",
")",
"throws",
"SAXException",
"{",
"if",
"(",
"localName",
".",
"compareToIgnoreCase",
"(",
"GPXTags",
... | Fires whenever an XML start markup is encountered. It indicates which
version of gpx file is to be parsed. It counts the waypoints, routes,
routepoints, tracks, track segments and trackpoints.
@param uri URI of the local element
@param localName Name of the local element (without prefix)
@param qName qName of the local element (with prefix)
@param attributes Attributes of the local element (contained in the
markup)
@throws SAXException Any SAX exception, possibly wrapping another
exception | [
"Fires",
"whenever",
"an",
"XML",
"start",
"markup",
"is",
"encountered",
".",
"It",
"indicates",
"which",
"version",
"of",
"gpx",
"file",
"is",
"to",
"be",
"parsed",
".",
"It",
"counts",
"the",
"waypoints",
"routes",
"routepoints",
"tracks",
"track",
"segme... | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/gpx/model/GpxPreparser.java#L100-L117 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java | CoordinatesUtils.contains3D | public static boolean contains3D(Coordinate[] coords, Coordinate coord) {
for (Coordinate coordinate : coords) {
if (coordinate.equals3D(coord)) {
return true;
}
}
return false;
} | java | public static boolean contains3D(Coordinate[] coords, Coordinate coord) {
for (Coordinate coordinate : coords) {
if (coordinate.equals3D(coord)) {
return true;
}
}
return false;
} | [
"public",
"static",
"boolean",
"contains3D",
"(",
"Coordinate",
"[",
"]",
"coords",
",",
"Coordinate",
"coord",
")",
"{",
"for",
"(",
"Coordinate",
"coordinate",
":",
"coords",
")",
"{",
"if",
"(",
"coordinate",
".",
"equals3D",
"(",
"coord",
")",
")",
"... | Check if a coordinate array contains a specific coordinate.
The equality is done in 3D (z values ARE checked).
@param coords
@param coord
@return | [
"Check",
"if",
"a",
"coordinate",
"array",
"contains",
"a",
"specific",
"coordinate",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java#L89-L96 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java | CoordinatesUtils.getFurthestCoordinate | public static Coordinate[] getFurthestCoordinate(Coordinate base, Coordinate[] coords) {
double distanceMax = Double.MIN_VALUE;
Coordinate farCoordinate = null;
for (Coordinate coord : coords) {
double distance = coord.distance(base);
if (distance > distanceMax) {
distanceMax = distance;
farCoordinate = coord;
}
}
if (farCoordinate != null) {
return new Coordinate[]{base, farCoordinate};
} else {
return null;
}
} | java | public static Coordinate[] getFurthestCoordinate(Coordinate base, Coordinate[] coords) {
double distanceMax = Double.MIN_VALUE;
Coordinate farCoordinate = null;
for (Coordinate coord : coords) {
double distance = coord.distance(base);
if (distance > distanceMax) {
distanceMax = distance;
farCoordinate = coord;
}
}
if (farCoordinate != null) {
return new Coordinate[]{base, farCoordinate};
} else {
return null;
}
} | [
"public",
"static",
"Coordinate",
"[",
"]",
"getFurthestCoordinate",
"(",
"Coordinate",
"base",
",",
"Coordinate",
"[",
"]",
"coords",
")",
"{",
"double",
"distanceMax",
"=",
"Double",
".",
"MIN_VALUE",
";",
"Coordinate",
"farCoordinate",
"=",
"null",
";",
"fo... | Find the furthest coordinate in a geometry from a base coordinate
@param base
@param coords
@return the base coordinate and the target coordinate | [
"Find",
"the",
"furthest",
"coordinate",
"in",
"a",
"geometry",
"from",
"a",
"base",
"coordinate"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java#L147-L163 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java | CoordinatesUtils.length3D | public static double length3D(CoordinateSequence pts) {
// optimized for processing CoordinateSequences
int n = pts.size();
if (n <= 1) {
return 0.0;
}
double len = 0.0;
Coordinate p = new Coordinate();
pts.getCoordinate(0, p);
double x0 = p.x;
double y0 = p.y;
double z0 = p.z;
if (Double.isNaN(z0)) {
return 0.0;
}
for (int i = 1; i < n; i++) {
pts.getCoordinate(i, p);
double x1 = p.x;
double y1 = p.y;
double z1 = p.z;
if (Double.isNaN(z1)) {
return 0.0;
}
double dx = x1 - x0;
double dy = y1 - y0;
double dz = z1 - z0;
len += Math.sqrt(dx * dx + dy * dy + dz * dz);
x0 = x1;
y0 = y1;
z0 = z1;
}
return len;
} | java | public static double length3D(CoordinateSequence pts) {
// optimized for processing CoordinateSequences
int n = pts.size();
if (n <= 1) {
return 0.0;
}
double len = 0.0;
Coordinate p = new Coordinate();
pts.getCoordinate(0, p);
double x0 = p.x;
double y0 = p.y;
double z0 = p.z;
if (Double.isNaN(z0)) {
return 0.0;
}
for (int i = 1; i < n; i++) {
pts.getCoordinate(i, p);
double x1 = p.x;
double y1 = p.y;
double z1 = p.z;
if (Double.isNaN(z1)) {
return 0.0;
}
double dx = x1 - x0;
double dy = y1 - y0;
double dz = z1 - z0;
len += Math.sqrt(dx * dx + dy * dy + dz * dz);
x0 = x1;
y0 = y1;
z0 = z1;
}
return len;
} | [
"public",
"static",
"double",
"length3D",
"(",
"CoordinateSequence",
"pts",
")",
"{",
"// optimized for processing CoordinateSequences",
"int",
"n",
"=",
"pts",
".",
"size",
"(",
")",
";",
"if",
"(",
"n",
"<=",
"1",
")",
"{",
"return",
"0.0",
";",
"}",
"do... | Computes the length of a linestring specified by a sequence of points.
if a coordinate has a NaN z return 0.
@param pts
the points specifying the linestring
@return the length of the linestring | [
"Computes",
"the",
"length",
"of",
"a",
"linestring",
"specified",
"by",
"a",
"sequence",
"of",
"points",
".",
"if",
"a",
"coordinate",
"has",
"a",
"NaN",
"z",
"return",
"0",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java#L173-L211 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java | CoordinatesUtils.length3D | public static double length3D(Geometry geom) {
double sum = 0;
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i);
if (subGeom instanceof Polygon) {
sum += length3D((Polygon) subGeom);
} else if (subGeom instanceof LineString) {
sum += length3D((LineString) subGeom);
}
}
return sum;
} | java | public static double length3D(Geometry geom) {
double sum = 0;
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i);
if (subGeom instanceof Polygon) {
sum += length3D((Polygon) subGeom);
} else if (subGeom instanceof LineString) {
sum += length3D((LineString) subGeom);
}
}
return sum;
} | [
"public",
"static",
"double",
"length3D",
"(",
"Geometry",
"geom",
")",
"{",
"double",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"geom",
".",
"getNumGeometries",
"(",
")",
";",
"i",
"++",
")",
"{",
"Geometry",
"subGeom"... | Returns the 3D length of the geometry
@param geom
@return | [
"Returns",
"the",
"3D",
"length",
"of",
"the",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java#L220-L231 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java | CoordinatesUtils.length3D | public static double length3D(Polygon polygon) {
double len = 0.0;
len += length3D(polygon.getExteriorRing().getCoordinateSequence());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
len += length3D(polygon.getInteriorRingN(i));
}
return len;
} | java | public static double length3D(Polygon polygon) {
double len = 0.0;
len += length3D(polygon.getExteriorRing().getCoordinateSequence());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
len += length3D(polygon.getInteriorRingN(i));
}
return len;
} | [
"public",
"static",
"double",
"length3D",
"(",
"Polygon",
"polygon",
")",
"{",
"double",
"len",
"=",
"0.0",
";",
"len",
"+=",
"length3D",
"(",
"polygon",
".",
"getExteriorRing",
"(",
")",
".",
"getCoordinateSequence",
"(",
")",
")",
";",
"for",
"(",
"int... | Returns the 3D perimeter of a polygon
@param polygon
@return | [
"Returns",
"the",
"3D",
"perimeter",
"of",
"a",
"polygon"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/CoordinatesUtils.java#L249-L256 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/system/IntegerRange.java | IntegerRange.createArray | public static ValueArray createArray(int begin, int end, int step) {
if (end < begin) {
throw new IllegalArgumentException("End must be greater or equal to begin");
}
int nbClasses = (int) ((end - begin) / step);
ValueInt[] getArray = new ValueInt[nbClasses];
for (int i = 0; i < nbClasses; i++) {
getArray[i] = ValueInt.get(i * step + begin);
}
return ValueArray.get(getArray);
} | java | public static ValueArray createArray(int begin, int end, int step) {
if (end < begin) {
throw new IllegalArgumentException("End must be greater or equal to begin");
}
int nbClasses = (int) ((end - begin) / step);
ValueInt[] getArray = new ValueInt[nbClasses];
for (int i = 0; i < nbClasses; i++) {
getArray[i] = ValueInt.get(i * step + begin);
}
return ValueArray.get(getArray);
} | [
"public",
"static",
"ValueArray",
"createArray",
"(",
"int",
"begin",
",",
"int",
"end",
",",
"int",
"step",
")",
"{",
"if",
"(",
"end",
"<",
"begin",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"End must be greater or equal to begin\"",
")",
... | Return an array of integers
@param begin from start
@param end to end
@param step increment
@return | [
"Return",
"an",
"array",
"of",
"integers"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/system/IntegerRange.java#L62-L73 | train |
orbisgis/h2gis | postgis-jts/src/main/java/org/h2gis/postgis_jts/Driver.java | Driver.mangleURL | public static String mangleURL(String url) throws SQLException {
if (url.startsWith(POSTGIS_H2PROTOCOL)) {
return POSTGIS_PROTOCOL + url.substring(POSTGIS_H2PROTOCOL.length());
} else {
throw new SQLException("Unknown protocol or subprotocol in url " + url);
}
} | java | public static String mangleURL(String url) throws SQLException {
if (url.startsWith(POSTGIS_H2PROTOCOL)) {
return POSTGIS_PROTOCOL + url.substring(POSTGIS_H2PROTOCOL.length());
} else {
throw new SQLException("Unknown protocol or subprotocol in url " + url);
}
} | [
"public",
"static",
"String",
"mangleURL",
"(",
"String",
"url",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"url",
".",
"startsWith",
"(",
"POSTGIS_H2PROTOCOL",
")",
")",
"{",
"return",
"POSTGIS_PROTOCOL",
"+",
"url",
".",
"substring",
"(",
"POSTGIS_H2PROT... | Mangles the PostGIS URL to return the original PostGreSQL URL.
@return Mangled PostGIS URL | [
"Mangles",
"the",
"PostGIS",
"URL",
"to",
"return",
"the",
"original",
"PostGreSQL",
"URL",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/postgis-jts/src/main/java/org/h2gis/postgis_jts/Driver.java#L62-L68 | train |
orbisgis/h2gis | postgis-jts/src/main/java/org/h2gis/postgis_jts/Driver.java | Driver.acceptsURL | public boolean acceptsURL(String url) {
try {
url = mangleURL(url);
} catch (SQLException e) {
return false;
}
return super.acceptsURL(url);
} | java | public boolean acceptsURL(String url) {
try {
url = mangleURL(url);
} catch (SQLException e) {
return false;
}
return super.acceptsURL(url);
} | [
"public",
"boolean",
"acceptsURL",
"(",
"String",
"url",
")",
"{",
"try",
"{",
"url",
"=",
"mangleURL",
"(",
"url",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"super",
".",
"acceptsURL",
"(",
"u... | Check whether the driver thinks he can handle the given URL.
@see java.sql.Driver#acceptsURL
@param url the URL of the driver.
@return true if this driver accepts the given URL. | [
"Check",
"whether",
"the",
"driver",
"thinks",
"he",
"can",
"handle",
"the",
"given",
"URL",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/postgis-jts/src/main/java/org/h2gis/postgis_jts/Driver.java#L79-L86 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.hasField | public static boolean hasField(Connection connection, String tableName, String fieldName) throws SQLException {
final Statement statement = connection.createStatement();
try {
final ResultSet resultSet = statement.executeQuery(
"SELECT * FROM " + TableLocation.parse(tableName) + " LIMIT 0;");
try {
return hasField(resultSet.getMetaData(), fieldName);
} finally {
resultSet.close();
}
} catch (SQLException ex) {
return false;
} finally {
statement.close();
}
} | java | public static boolean hasField(Connection connection, String tableName, String fieldName) throws SQLException {
final Statement statement = connection.createStatement();
try {
final ResultSet resultSet = statement.executeQuery(
"SELECT * FROM " + TableLocation.parse(tableName) + " LIMIT 0;");
try {
return hasField(resultSet.getMetaData(), fieldName);
} finally {
resultSet.close();
}
} catch (SQLException ex) {
return false;
} finally {
statement.close();
}
} | [
"public",
"static",
"boolean",
"hasField",
"(",
"Connection",
"connection",
",",
"String",
"tableName",
",",
"String",
"fieldName",
")",
"throws",
"SQLException",
"{",
"final",
"Statement",
"statement",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"... | Return true if table tableName contains field fieldName.
@param connection Connection
@param tableName Table name
@param fieldName Field name
@return True if the table contains the field
@throws SQLException | [
"Return",
"true",
"if",
"table",
"tableName",
"contains",
"field",
"fieldName",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L89-L104 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getFieldIndex | public static int getFieldIndex(ResultSetMetaData resultSetMetaData, String fieldName) throws SQLException {
for(int columnId = 1; columnId <= resultSetMetaData.getColumnCount(); columnId++) {
if(fieldName.equalsIgnoreCase(resultSetMetaData.getColumnName(columnId))) {
return columnId;
}
}
return -1;
} | java | public static int getFieldIndex(ResultSetMetaData resultSetMetaData, String fieldName) throws SQLException {
for(int columnId = 1; columnId <= resultSetMetaData.getColumnCount(); columnId++) {
if(fieldName.equalsIgnoreCase(resultSetMetaData.getColumnName(columnId))) {
return columnId;
}
}
return -1;
} | [
"public",
"static",
"int",
"getFieldIndex",
"(",
"ResultSetMetaData",
"resultSetMetaData",
",",
"String",
"fieldName",
")",
"throws",
"SQLException",
"{",
"for",
"(",
"int",
"columnId",
"=",
"1",
";",
"columnId",
"<=",
"resultSetMetaData",
".",
"getColumnCount",
"... | Fetch the metadata, and check field name
@param resultSetMetaData Active result set meta data.
@param fieldName Field name, ignore case
@return The field index [1-n]; -1 if the field is not found
@throws SQLException | [
"Fetch",
"the",
"metadata",
"and",
"check",
"field",
"name"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L117-L124 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getFieldNames | public static List<String> getFieldNames(DatabaseMetaData meta, String table) throws SQLException {
List<String> fieldNameList = new ArrayList<String>();
TableLocation location = TableLocation.parse(table);
ResultSet rs = meta.getColumns(location.getCatalog(null), location.getSchema(null), location.getTable(), null);
try {
while(rs.next()) {
fieldNameList.add(rs.getString("COLUMN_NAME"));
}
} finally {
rs.close();
}
return fieldNameList;
} | java | public static List<String> getFieldNames(DatabaseMetaData meta, String table) throws SQLException {
List<String> fieldNameList = new ArrayList<String>();
TableLocation location = TableLocation.parse(table);
ResultSet rs = meta.getColumns(location.getCatalog(null), location.getSchema(null), location.getTable(), null);
try {
while(rs.next()) {
fieldNameList.add(rs.getString("COLUMN_NAME"));
}
} finally {
rs.close();
}
return fieldNameList;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getFieldNames",
"(",
"DatabaseMetaData",
"meta",
",",
"String",
"table",
")",
"throws",
"SQLException",
"{",
"List",
"<",
"String",
">",
"fieldNameList",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
... | Returns the list of all the field name of a table.
@param meta DataBase meta data
@param table Table identifier [[catalog.]schema.]table
@return The list of field name.
@throws SQLException If jdbc throws an error | [
"Returns",
"the",
"list",
"of",
"all",
"the",
"field",
"name",
"of",
"a",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L156-L168 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getRowCount | public static int getRowCount(Connection connection, String tableReference) throws SQLException {
Statement st = connection.createStatement();
int rowCount = 0;
try {
ResultSet rs = st.executeQuery(String.format("select count(*) rowcount from %s", TableLocation.parse(tableReference)));
try {
if(rs.next()) {
rowCount = rs.getInt(1);
}
} finally {
rs.close();
}
}finally {
st.close();
}
return rowCount;
} | java | public static int getRowCount(Connection connection, String tableReference) throws SQLException {
Statement st = connection.createStatement();
int rowCount = 0;
try {
ResultSet rs = st.executeQuery(String.format("select count(*) rowcount from %s", TableLocation.parse(tableReference)));
try {
if(rs.next()) {
rowCount = rs.getInt(1);
}
} finally {
rs.close();
}
}finally {
st.close();
}
return rowCount;
} | [
"public",
"static",
"int",
"getRowCount",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"int",
"rowCount",
"=",
"0",
";",
"try"... | Fetch the row count of a table.
@param connection Active connection.
@param tableReference Table reference
@return Row count
@throws SQLException If the table does not exists, or sql request fail. | [
"Fetch",
"the",
"row",
"count",
"of",
"a",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L177-L193 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.isTemporaryTable | public static boolean isTemporaryTable(Connection connection, String tableReference) throws SQLException {
TableLocation location = TableLocation.parse(tableReference);
ResultSet rs = getTablesView(connection, location.getCatalog(), location.getSchema(), location.getTable());
boolean isTemporary = false;
try {
if(rs.next()) {
String tableType;
if(hasField(rs.getMetaData(), "STORAGE_TYPE")) {
// H2
tableType = rs.getString("STORAGE_TYPE");
} else {
// Standard SQL
tableType = rs.getString("TABLE_TYPE");
}
isTemporary = tableType.contains("TEMPORARY");
} else {
throw new SQLException("The table "+location+" does not exists");
}
} finally {
rs.close();
}
return isTemporary;
} | java | public static boolean isTemporaryTable(Connection connection, String tableReference) throws SQLException {
TableLocation location = TableLocation.parse(tableReference);
ResultSet rs = getTablesView(connection, location.getCatalog(), location.getSchema(), location.getTable());
boolean isTemporary = false;
try {
if(rs.next()) {
String tableType;
if(hasField(rs.getMetaData(), "STORAGE_TYPE")) {
// H2
tableType = rs.getString("STORAGE_TYPE");
} else {
// Standard SQL
tableType = rs.getString("TABLE_TYPE");
}
isTemporary = tableType.contains("TEMPORARY");
} else {
throw new SQLException("The table "+location+" does not exists");
}
} finally {
rs.close();
}
return isTemporary;
} | [
"public",
"static",
"boolean",
"isTemporaryTable",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
")",
"throws",
"SQLException",
"{",
"TableLocation",
"location",
"=",
"TableLocation",
".",
"parse",
"(",
"tableReference",
")",
";",
"ResultSet",
"r... | Read INFORMATION_SCHEMA.TABLES in order to see if the provided table reference is a temporary table.
@param connection Active connection not closed by this method
@param tableReference Table reference
@return True if the provided table is temporary.
@throws SQLException If the table does not exists. | [
"Read",
"INFORMATION_SCHEMA",
".",
"TABLES",
"in",
"order",
"to",
"see",
"if",
"the",
"provided",
"table",
"reference",
"is",
"a",
"temporary",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L202-L224 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.isLinkedTable | public static boolean isLinkedTable(Connection connection, String tableReference) throws SQLException {
TableLocation location = TableLocation.parse(tableReference);
ResultSet rs = getTablesView(connection, location.getCatalog(), location.getSchema(), location.getTable());
boolean isLinked;
try {
if(rs.next()) {
String tableType = rs.getString("TABLE_TYPE");
isLinked = tableType.contains("TABLE LINK");
} else {
throw new SQLException("The table "+location+" does not exists");
}
} finally {
rs.close();
}
return isLinked;
} | java | public static boolean isLinkedTable(Connection connection, String tableReference) throws SQLException {
TableLocation location = TableLocation.parse(tableReference);
ResultSet rs = getTablesView(connection, location.getCatalog(), location.getSchema(), location.getTable());
boolean isLinked;
try {
if(rs.next()) {
String tableType = rs.getString("TABLE_TYPE");
isLinked = tableType.contains("TABLE LINK");
} else {
throw new SQLException("The table "+location+" does not exists");
}
} finally {
rs.close();
}
return isLinked;
} | [
"public",
"static",
"boolean",
"isLinkedTable",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
")",
"throws",
"SQLException",
"{",
"TableLocation",
"location",
"=",
"TableLocation",
".",
"parse",
"(",
"tableReference",
")",
";",
"ResultSet",
"rs",... | Read INFORMATION_SCHEMA.TABLES in order to see if the provided table reference is a linked table.
@param connection Active connection not closed by this method
@param tableReference Table reference
@return True if the provided table is linked.
@throws SQLException If the table does not exists. | [
"Read",
"INFORMATION_SCHEMA",
".",
"TABLES",
"in",
"order",
"to",
"see",
"if",
"the",
"provided",
"table",
"reference",
"is",
"a",
"linked",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L233-L248 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.tableExists | public static boolean tableExists(Connection connection, String tableName) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("SELECT * FROM " + TableLocation.parse(tableName) + " LIMIT 0;");
return true;
} catch (SQLException ex) {
return false;
}
} | java | public static boolean tableExists(Connection connection, String tableName) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("SELECT * FROM " + TableLocation.parse(tableName) + " LIMIT 0;");
return true;
} catch (SQLException ex) {
return false;
}
} | [
"public",
"static",
"boolean",
"tableExists",
"(",
"Connection",
"connection",
",",
"String",
"tableName",
")",
"throws",
"SQLException",
"{",
"try",
"(",
"Statement",
"statement",
"=",
"connection",
".",
"createStatement",
"(",
")",
")",
"{",
"statement",
".",
... | Return true if the table exists.
@param connection Connection
@param tableName Table name
@return true if the table exists
@throws java.sql.SQLException | [
"Return",
"true",
"if",
"the",
"table",
"exists",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L319-L326 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getTableNames | public static List<String> getTableNames(DatabaseMetaData metaData, String catalog, String schemaPattern,
String tableNamePattern, String [] types) throws SQLException {
List<String> tableList = new ArrayList<String>();
ResultSet rs = metaData.getTables(catalog, schemaPattern, tableNamePattern, types);
boolean isH2 = isH2DataBase(metaData);
try {
while (rs.next()) {
tableList.add(new TableLocation(rs).toString(isH2));
}
} finally {
rs.close();
}
return tableList;
} | java | public static List<String> getTableNames(DatabaseMetaData metaData, String catalog, String schemaPattern,
String tableNamePattern, String [] types) throws SQLException {
List<String> tableList = new ArrayList<String>();
ResultSet rs = metaData.getTables(catalog, schemaPattern, tableNamePattern, types);
boolean isH2 = isH2DataBase(metaData);
try {
while (rs.next()) {
tableList.add(new TableLocation(rs).toString(isH2));
}
} finally {
rs.close();
}
return tableList;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getTableNames",
"(",
"DatabaseMetaData",
"metaData",
",",
"String",
"catalog",
",",
"String",
"schemaPattern",
",",
"String",
"tableNamePattern",
",",
"String",
"[",
"]",
"types",
")",
"throws",
"SQLException",
"{... | Returns the list of table names.
@param metaData Database meta data
@param catalog A catalog name. Must match the catalog name as it is stored in the database.
"" retrieves those without a catalog; null means that the catalog name should not be used to
narrow the search
@param schemaPattern A schema name pattern. Must match the schema name as it is stored in the database.
"" retrieves those without a schema.
null means that the schema name should not be used to narrow the search
@param tableNamePattern A table name pattern. Must match the table name as it is stored in the database
@param types A list of table types, which must be from the list of table types returned from getTableTypes(),
to include. null returns all types
@return The integer primary key used for edition[1-n]; 0 if the source is closed or if the table has no primary
key or more than one column as primary key | [
"Returns",
"the",
"list",
"of",
"table",
"names",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L344-L357 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getUniqueFieldValues | public static List<String> getUniqueFieldValues(Connection connection, String tableName, String fieldName) throws SQLException {
final Statement statement = connection.createStatement();
List<String> fieldValues = new ArrayList<String>();
try {
ResultSet result = statement.executeQuery("SELECT DISTINCT "+TableLocation.quoteIdentifier(fieldName)+" FROM "+TableLocation.parse(tableName));
while(result.next()){
fieldValues.add(result.getString(1));
}
} finally {
statement.close();
}
return fieldValues;
} | java | public static List<String> getUniqueFieldValues(Connection connection, String tableName, String fieldName) throws SQLException {
final Statement statement = connection.createStatement();
List<String> fieldValues = new ArrayList<String>();
try {
ResultSet result = statement.executeQuery("SELECT DISTINCT "+TableLocation.quoteIdentifier(fieldName)+" FROM "+TableLocation.parse(tableName));
while(result.next()){
fieldValues.add(result.getString(1));
}
} finally {
statement.close();
}
return fieldValues;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getUniqueFieldValues",
"(",
"Connection",
"connection",
",",
"String",
"tableName",
",",
"String",
"fieldName",
")",
"throws",
"SQLException",
"{",
"final",
"Statement",
"statement",
"=",
"connection",
".",
"createS... | Returns the list of distinct values contained by a field from a table from the database
@param connection Connection
@param tableName Name of the table containing the field.
@param fieldName Name of the field containing the values.
@return The list of distinct values of the field. | [
"Returns",
"the",
"list",
"of",
"distinct",
"values",
"contained",
"by",
"a",
"field",
"from",
"a",
"table",
"from",
"the",
"database"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L367-L379 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java | JDBCUtilities.getFieldNames | public static List<String> getFieldNames(ResultSetMetaData resultSetMetaData) throws SQLException {
List<String> columnNames = new ArrayList<>();
int cols = resultSetMetaData.getColumnCount();
for (int i = 1; i <= cols; i++) {
columnNames.add(resultSetMetaData.getColumnName(i));
}
return columnNames;
} | java | public static List<String> getFieldNames(ResultSetMetaData resultSetMetaData) throws SQLException {
List<String> columnNames = new ArrayList<>();
int cols = resultSetMetaData.getColumnCount();
for (int i = 1; i <= cols; i++) {
columnNames.add(resultSetMetaData.getColumnName(i));
}
return columnNames;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getFieldNames",
"(",
"ResultSetMetaData",
"resultSetMetaData",
")",
"throws",
"SQLException",
"{",
"List",
"<",
"String",
">",
"columnNames",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"int",
"cols",
"=",
"... | Fetch the name of columns
@param resultSetMetaData Active result set meta data.
@return An array with all column names
@throws SQLException | [
"Fetch",
"the",
"name",
"of",
"columns"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/JDBCUtilities.java#L399-L406 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFEngine.java | DBFEngine.feedTableDataFromHeader | public static void feedTableDataFromHeader(DbaseFileHeader header, CreateTableData data) throws IOException {
for (int i = 0; i < header.getNumFields(); i++) {
String fieldsName = header.getFieldName(i);
final int type = dbfTypeToH2Type(header,i);
Column column = new Column(fieldsName.toUpperCase(), type);
column.setPrecision(header.getFieldLength(i)); // set string length
data.columns.add(column);
}
} | java | public static void feedTableDataFromHeader(DbaseFileHeader header, CreateTableData data) throws IOException {
for (int i = 0; i < header.getNumFields(); i++) {
String fieldsName = header.getFieldName(i);
final int type = dbfTypeToH2Type(header,i);
Column column = new Column(fieldsName.toUpperCase(), type);
column.setPrecision(header.getFieldLength(i)); // set string length
data.columns.add(column);
}
} | [
"public",
"static",
"void",
"feedTableDataFromHeader",
"(",
"DbaseFileHeader",
"header",
",",
"CreateTableData",
"data",
")",
"throws",
"IOException",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"header",
".",
"getNumFields",
"(",
")",
";",
"i",
... | Parse the DBF file then init the provided data structure
@param header dbf header
@param data Data to initialise
@throws java.io.IOException | [
"Parse",
"the",
"DBF",
"file",
"then",
"init",
"the",
"provided",
"data",
"structure"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFEngine.java#L59-L67 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/utility/WriteBufferManager.java | WriteBufferManager.prepareToAddBytes | private void prepareToAddBytes(int numBytes) throws IOException {
if (buffer.remaining() < numBytes) {
buffer.flip();
channel.write(buffer);
int bufferCapacity = Math.max(BUFFER_SIZE, numBytes);
if (bufferCapacity != buffer.capacity()) {
ByteOrder order = buffer.order();
buffer = ByteBuffer.allocate(bufferCapacity);
buffer.order(order);
} else {
buffer.clear();
}
}
} | java | private void prepareToAddBytes(int numBytes) throws IOException {
if (buffer.remaining() < numBytes) {
buffer.flip();
channel.write(buffer);
int bufferCapacity = Math.max(BUFFER_SIZE, numBytes);
if (bufferCapacity != buffer.capacity()) {
ByteOrder order = buffer.order();
buffer = ByteBuffer.allocate(bufferCapacity);
buffer.order(order);
} else {
buffer.clear();
}
}
} | [
"private",
"void",
"prepareToAddBytes",
"(",
"int",
"numBytes",
")",
"throws",
"IOException",
"{",
"if",
"(",
"buffer",
".",
"remaining",
"(",
")",
"<",
"numBytes",
")",
"{",
"buffer",
".",
"flip",
"(",
")",
";",
"channel",
".",
"write",
"(",
"buffer",
... | Moves the window
@param numBytes
@throws java.io.IOException | [
"Moves",
"the",
"window"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/utility/WriteBufferManager.java#L70-L84 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_ToMultiPoint.java | ST_ToMultiPoint.createMultiPoint | public static MultiPoint createMultiPoint(Geometry geom) {
if (geom != null) {
return GEOMETRY_FACTORY.createMultiPoint(geom.getCoordinates());
} else {
return null;
}
} | java | public static MultiPoint createMultiPoint(Geometry geom) {
if (geom != null) {
return GEOMETRY_FACTORY.createMultiPoint(geom.getCoordinates());
} else {
return null;
}
} | [
"public",
"static",
"MultiPoint",
"createMultiPoint",
"(",
"Geometry",
"geom",
")",
"{",
"if",
"(",
"geom",
"!=",
"null",
")",
"{",
"return",
"GEOMETRY_FACTORY",
".",
"createMultiPoint",
"(",
"geom",
".",
"getCoordinates",
"(",
")",
")",
";",
"}",
"else",
... | Constructs a MultiPoint from the given geometry's coordinates.
@param geom Geometry
@return A MultiPoint constructed from the given geometry's coordinates | [
"Constructs",
"a",
"MultiPoint",
"from",
"the",
"given",
"geometry",
"s",
"coordinates",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_ToMultiPoint.java#L53-L59 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/tsv/TSVWrite.java | TSVWrite.writeTSV | public static void writeTSV(Connection connection, String fileName, String tableReference, String encoding) throws SQLException, IOException {
TSVDriverFunction tSVDriverFunction = new TSVDriverFunction();
tSVDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding);
} | java | public static void writeTSV(Connection connection, String fileName, String tableReference, String encoding) throws SQLException, IOException {
TSVDriverFunction tSVDriverFunction = new TSVDriverFunction();
tSVDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding);
} | [
"public",
"static",
"void",
"writeTSV",
"(",
"Connection",
"connection",
",",
"String",
"fileName",
",",
"String",
"tableReference",
",",
"String",
"encoding",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"TSVDriverFunction",
"tSVDriverFunction",
"=",
"ne... | Export a table into a Tab-separated values file
@param connection
@param fileName
@param tableReference
@param encoding
@throws SQLException
@throws IOException | [
"Export",
"a",
"table",
"into",
"a",
"Tab",
"-",
"separated",
"values",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/tsv/TSVWrite.java#L71-L74 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_MakeEllipse.java | ST_MakeEllipse.makeEllipse | public static Polygon makeEllipse(Point p, double width, double height) throws SQLException {
if(p == null){
return null;
}
if (height < 0 || width < 0) {
throw new SQLException("Both width and height must be positive.");
} else {
GSF.setCentre(new Coordinate(p.getX(), p.getY()));
GSF.setWidth(width);
GSF.setHeight(height);
return GSF.createEllipse();
}
} | java | public static Polygon makeEllipse(Point p, double width, double height) throws SQLException {
if(p == null){
return null;
}
if (height < 0 || width < 0) {
throw new SQLException("Both width and height must be positive.");
} else {
GSF.setCentre(new Coordinate(p.getX(), p.getY()));
GSF.setWidth(width);
GSF.setHeight(height);
return GSF.createEllipse();
}
} | [
"public",
"static",
"Polygon",
"makeEllipse",
"(",
"Point",
"p",
",",
"double",
"width",
",",
"double",
"height",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"p",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"height",
"<",
"0",
"... | Make an ellipse centered at the given point with the given width and
height.
@param p Point
@param width Width
@param height Height
@return An ellipse centered at the given point with the given width and height
@throws SQLException if the width or height is non-positive | [
"Make",
"an",
"ellipse",
"centered",
"at",
"the",
"given",
"point",
"with",
"the",
"given",
"width",
"and",
"height",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_MakeEllipse.java#L64-L76 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_MakeGridPoints.java | ST_MakeGridPoints.createGridPoints | public static ResultSet createGridPoints(Connection connection, Value value, double deltaX, double deltaY) throws SQLException {
if(value == null){
return null;
}
if (value instanceof ValueString) {
GridRowSet gridRowSet = new GridRowSet(connection, deltaX, deltaY, value.getString());
gridRowSet.setCenterCell(true);
return gridRowSet.getResultSet();
} else if (value instanceof ValueGeometry) {
ValueGeometry geom = (ValueGeometry) value;
GridRowSet gridRowSet = new GridRowSet(connection, deltaX, deltaY, geom.getGeometry().getEnvelopeInternal());
gridRowSet.setCenterCell(true);
return gridRowSet.getResultSet();
} else {
throw new SQLException("This function supports only table name or geometry as first argument.");
}
} | java | public static ResultSet createGridPoints(Connection connection, Value value, double deltaX, double deltaY) throws SQLException {
if(value == null){
return null;
}
if (value instanceof ValueString) {
GridRowSet gridRowSet = new GridRowSet(connection, deltaX, deltaY, value.getString());
gridRowSet.setCenterCell(true);
return gridRowSet.getResultSet();
} else if (value instanceof ValueGeometry) {
ValueGeometry geom = (ValueGeometry) value;
GridRowSet gridRowSet = new GridRowSet(connection, deltaX, deltaY, geom.getGeometry().getEnvelopeInternal());
gridRowSet.setCenterCell(true);
return gridRowSet.getResultSet();
} else {
throw new SQLException("This function supports only table name or geometry as first argument.");
}
} | [
"public",
"static",
"ResultSet",
"createGridPoints",
"(",
"Connection",
"connection",
",",
"Value",
"value",
",",
"double",
"deltaX",
",",
"double",
"deltaY",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"return",
"null",
"... | Create a regular grid of points using the first input value to compute
the full extent.
@param connection
@param value could be the name of a table or a geometry.
@param deltaX the X cell size
@param deltaY the Y cell size
@return a resultset that contains all cells as a set of polygons
@throws SQLException | [
"Create",
"a",
"regular",
"grid",
"of",
"points",
"using",
"the",
"first",
"input",
"value",
"to",
"compute",
"the",
"full",
"extent",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/create/ST_MakeGridPoints.java#L66-L82 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/json/JsonDriverFunction.java | JsonDriverFunction.exportTable | @Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException {
JsonWriteDriver jsonDriver = new JsonWriteDriver(connection);
jsonDriver.write(progress,tableReference, fileName, encoding);
} | java | @Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException {
JsonWriteDriver jsonDriver = new JsonWriteDriver(connection);
jsonDriver.write(progress,tableReference, fileName, encoding);
} | [
"@",
"Override",
"public",
"void",
"exportTable",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
",",
"File",
"fileName",
",",
"ProgressVisitor",
"progress",
",",
"String",
"encoding",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"Jso... | Save a table or a query to JSON file
@param connection
@param tableReference
@param fileName
@param progress
@param encoding
@throws SQLException
@throws IOException | [
"Save",
"a",
"table",
"or",
"a",
"query",
"to",
"JSON",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/json/JsonDriverFunction.java#L81-L85 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/Voronoi.java | Voronoi.getOrAppendVertex | private int getOrAppendVertex(Coordinate newCoord, Quadtree ptQuad) {
Envelope queryEnv = new Envelope(newCoord);
queryEnv.expandBy(epsilon);
QuadTreeVisitor visitor = new QuadTreeVisitor(epsilon, newCoord);
try {
ptQuad.query(queryEnv, visitor);
} catch (RuntimeException ex) {
//ignore
}
if (visitor.getNearest() != null) {
return visitor.getNearest().index;
}
// Not found then
// Append to the list and QuadTree
EnvelopeWithIndex ret = new EnvelopeWithIndex(triVertex.size(), newCoord);
ptQuad.insert(queryEnv, ret);
triVertex.add(ret);
return ret.index;
} | java | private int getOrAppendVertex(Coordinate newCoord, Quadtree ptQuad) {
Envelope queryEnv = new Envelope(newCoord);
queryEnv.expandBy(epsilon);
QuadTreeVisitor visitor = new QuadTreeVisitor(epsilon, newCoord);
try {
ptQuad.query(queryEnv, visitor);
} catch (RuntimeException ex) {
//ignore
}
if (visitor.getNearest() != null) {
return visitor.getNearest().index;
}
// Not found then
// Append to the list and QuadTree
EnvelopeWithIndex ret = new EnvelopeWithIndex(triVertex.size(), newCoord);
ptQuad.insert(queryEnv, ret);
triVertex.add(ret);
return ret.index;
} | [
"private",
"int",
"getOrAppendVertex",
"(",
"Coordinate",
"newCoord",
",",
"Quadtree",
"ptQuad",
")",
"{",
"Envelope",
"queryEnv",
"=",
"new",
"Envelope",
"(",
"newCoord",
")",
";",
"queryEnv",
".",
"expandBy",
"(",
"epsilon",
")",
";",
"QuadTreeVisitor",
"vis... | Compute unique index for the coordinate
Index count from 0 to n
If the new vertex is closer than distMerge with an another vertex then it will return its index.
@return The index of the vertex | [
"Compute",
"unique",
"index",
"for",
"the",
"coordinate",
"Index",
"count",
"from",
"0",
"to",
"n",
"If",
"the",
"new",
"vertex",
"is",
"closer",
"than",
"distMerge",
"with",
"an",
"another",
"vertex",
"then",
"it",
"will",
"return",
"its",
"index",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/Voronoi.java#L89-L107 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/Voronoi.java | Voronoi.generateTriangleNeighbors | public Triple[] generateTriangleNeighbors(Geometry geometry) throws TopologyException {
inputTriangles = geometry;
CoordinateSequenceDimensionFilter sequenceDimensionFilter = new CoordinateSequenceDimensionFilter();
geometry.apply(sequenceDimensionFilter);
hasZ = sequenceDimensionFilter.getDimension() == CoordinateSequenceDimensionFilter.XYZ;
Quadtree ptQuad = new Quadtree();
// In order to compute triangle neighbors we have to set a unique id to points.
triangleVertex = new Triple[geometry.getNumGeometries()];
// Final size of tri vertex is not known at the moment. Give just an hint
triVertex = new ArrayList<EnvelopeWithIndex>(triangleVertex.length);
// First Loop make an index of triangle vertex
for(int idgeom = 0; idgeom < triangleVertex.length; idgeom++) {
Geometry geomItem = geometry.getGeometryN(idgeom);
if(geomItem instanceof Polygon) {
Coordinate[] coords = geomItem.getCoordinates();
if(coords.length != 4) {
throw new TopologyException("Voronoi method accept only triangles");
}
triangleVertex[idgeom] = new Triple(getOrAppendVertex(coords[0], ptQuad),
getOrAppendVertex(coords[1], ptQuad), getOrAppendVertex(coords[2], ptQuad));
for(int triVertexIndex : triangleVertex[idgeom].toArray()) {
triVertex.get(triVertexIndex).addSharingTriangle(idgeom);
}
} else {
throw new TopologyException("Voronoi method accept only polygons");
}
}
// Second loop make an index of triangle neighbors
ptQuad = null;
triangleNeighbors = new Triple[geometry.getNumGeometries()];
for(int triId = 0; triId< triangleVertex.length; triId++) {
Triple triangleIndex = triangleVertex[triId];
triangleNeighbors[triId] = new Triple(commonEdge(triId,triVertex.get(triangleIndex.getB()), triVertex.get(triangleIndex.getC())),
commonEdge(triId,triVertex.get(triangleIndex.getA()), triVertex.get(triangleIndex.getC())),
commonEdge(triId,triVertex.get(triangleIndex.getB()), triVertex.get(triangleIndex.getA())));
}
triVertex.clear();
return triangleNeighbors;
} | java | public Triple[] generateTriangleNeighbors(Geometry geometry) throws TopologyException {
inputTriangles = geometry;
CoordinateSequenceDimensionFilter sequenceDimensionFilter = new CoordinateSequenceDimensionFilter();
geometry.apply(sequenceDimensionFilter);
hasZ = sequenceDimensionFilter.getDimension() == CoordinateSequenceDimensionFilter.XYZ;
Quadtree ptQuad = new Quadtree();
// In order to compute triangle neighbors we have to set a unique id to points.
triangleVertex = new Triple[geometry.getNumGeometries()];
// Final size of tri vertex is not known at the moment. Give just an hint
triVertex = new ArrayList<EnvelopeWithIndex>(triangleVertex.length);
// First Loop make an index of triangle vertex
for(int idgeom = 0; idgeom < triangleVertex.length; idgeom++) {
Geometry geomItem = geometry.getGeometryN(idgeom);
if(geomItem instanceof Polygon) {
Coordinate[] coords = geomItem.getCoordinates();
if(coords.length != 4) {
throw new TopologyException("Voronoi method accept only triangles");
}
triangleVertex[idgeom] = new Triple(getOrAppendVertex(coords[0], ptQuad),
getOrAppendVertex(coords[1], ptQuad), getOrAppendVertex(coords[2], ptQuad));
for(int triVertexIndex : triangleVertex[idgeom].toArray()) {
triVertex.get(triVertexIndex).addSharingTriangle(idgeom);
}
} else {
throw new TopologyException("Voronoi method accept only polygons");
}
}
// Second loop make an index of triangle neighbors
ptQuad = null;
triangleNeighbors = new Triple[geometry.getNumGeometries()];
for(int triId = 0; triId< triangleVertex.length; triId++) {
Triple triangleIndex = triangleVertex[triId];
triangleNeighbors[triId] = new Triple(commonEdge(triId,triVertex.get(triangleIndex.getB()), triVertex.get(triangleIndex.getC())),
commonEdge(triId,triVertex.get(triangleIndex.getA()), triVertex.get(triangleIndex.getC())),
commonEdge(triId,triVertex.get(triangleIndex.getB()), triVertex.get(triangleIndex.getA())));
}
triVertex.clear();
return triangleNeighbors;
} | [
"public",
"Triple",
"[",
"]",
"generateTriangleNeighbors",
"(",
"Geometry",
"geometry",
")",
"throws",
"TopologyException",
"{",
"inputTriangles",
"=",
"geometry",
";",
"CoordinateSequenceDimensionFilter",
"sequenceDimensionFilter",
"=",
"new",
"CoordinateSequenceDimensionFil... | Given the input TIN, construct a graph of triangle.
@param geometry Collection of Polygon with 3 vertex.
@return Array of triangle neighbors. Order and count is the same of the input array.
@throws TopologyException If incompatible type geometry is given | [
"Given",
"the",
"input",
"TIN",
"construct",
"a",
"graph",
"of",
"triangle",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/jts_utils/Voronoi.java#L115-L153 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.registerGeometryType | public static void registerGeometryType(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for(DomainInfo domainInfo : getBuiltInsType()) {
// Check for byte array first, to not throw an enigmatic error CastException
st.execute("CREATE DOMAIN IF NOT EXISTS "+domainInfo.getDomainName()+" AS "+GEOMETRY_BASE_TYPE+"("+domainInfo.getGeometryTypeCode()+") CHECK (ST_GeometryTypeCode(VALUE) = "+domainInfo.getGeometryTypeCode()+");");
}
} | java | public static void registerGeometryType(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for(DomainInfo domainInfo : getBuiltInsType()) {
// Check for byte array first, to not throw an enigmatic error CastException
st.execute("CREATE DOMAIN IF NOT EXISTS "+domainInfo.getDomainName()+" AS "+GEOMETRY_BASE_TYPE+"("+domainInfo.getGeometryTypeCode()+") CHECK (ST_GeometryTypeCode(VALUE) = "+domainInfo.getGeometryTypeCode()+");");
}
} | [
"public",
"static",
"void",
"registerGeometryType",
"(",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"for",
"(",
"DomainInfo",
"domainInfo",
":",
"getBuiltInsType",
"(... | Register geometry type in an OSGi environment
@param connection Active H2 connection
@throws SQLException | [
"Register",
"geometry",
"type",
"in",
"an",
"OSGi",
"environment"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L362-L368 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.registerSpatialTables | public static void registerSpatialTables(Connection connection) throws SQLException {
Statement st = connection.createStatement();
st.execute("drop view if exists geometry_columns");
st.execute("create view geometry_columns as select TABLE_CATALOG f_table_catalog,TABLE_SCHEMA f_table_schema,TABLE_NAME f_table_name," +
"COLUMN_NAME f_geometry_column,1 storage_type,_GeometryTypeFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) geometry_type," +
"_DimensionFromConstraint(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) coord_dimension," +
"_ColumnSRID(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) srid," +
" _GeometryTypeNameFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) type" +
" from INFORMATION_SCHEMA.COLUMNS WHERE TYPE_NAME = 'GEOMETRY'");
ResultSet rs = connection.getMetaData().getTables("","PUBLIC","SPATIAL_REF_SYS",null);
if(!rs.next()) {
InputStreamReader reader = new InputStreamReader(
H2GISFunctions.class.getResourceAsStream("spatial_ref_sys.sql"));
RunScript.execute(connection, reader);
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} | java | public static void registerSpatialTables(Connection connection) throws SQLException {
Statement st = connection.createStatement();
st.execute("drop view if exists geometry_columns");
st.execute("create view geometry_columns as select TABLE_CATALOG f_table_catalog,TABLE_SCHEMA f_table_schema,TABLE_NAME f_table_name," +
"COLUMN_NAME f_geometry_column,1 storage_type,_GeometryTypeFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) geometry_type," +
"_DimensionFromConstraint(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) coord_dimension," +
"_ColumnSRID(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) srid," +
" _GeometryTypeNameFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) type" +
" from INFORMATION_SCHEMA.COLUMNS WHERE TYPE_NAME = 'GEOMETRY'");
ResultSet rs = connection.getMetaData().getTables("","PUBLIC","SPATIAL_REF_SYS",null);
if(!rs.next()) {
InputStreamReader reader = new InputStreamReader(
H2GISFunctions.class.getResourceAsStream("spatial_ref_sys.sql"));
RunScript.execute(connection, reader);
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} | [
"public",
"static",
"void",
"registerSpatialTables",
"(",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"st",
".",
"execute",
"(",
"\"drop view if exists geometry_columns\""... | Register view in order to create GEOMETRY_COLUMNS standard table.
@param connection Open connection
@throws java.sql.SQLException | [
"Register",
"view",
"in",
"order",
"to",
"create",
"GEOMETRY_COLUMNS",
"standard",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L375-L396 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.unRegisterGeometryType | public static void unRegisterGeometryType(Connection connection) throws SQLException {
Statement st = connection.createStatement();
DomainInfo[] domainInfos = getBuiltInsType();
for(DomainInfo domainInfo : domainInfos) {
st.execute("DROP DOMAIN IF EXISTS " + domainInfo.getDomainName());
}
} | java | public static void unRegisterGeometryType(Connection connection) throws SQLException {
Statement st = connection.createStatement();
DomainInfo[] domainInfos = getBuiltInsType();
for(DomainInfo domainInfo : domainInfos) {
st.execute("DROP DOMAIN IF EXISTS " + domainInfo.getDomainName());
}
} | [
"public",
"static",
"void",
"unRegisterGeometryType",
"(",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"DomainInfo",
"[",
"]",
"domainInfos",
"=",
"getBuiltInsType",
"... | Release geometry type
@param connection Active h2 connection with DROP DOMAIN and DROP ALIAS rights
@throws java.sql.SQLException | [
"Release",
"geometry",
"type"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L403-L409 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.getStringProperty | private static String getStringProperty(Function function, String propertyKey) {
Object value = function.getProperty(propertyKey);
return value instanceof String ? (String)value : "";
} | java | private static String getStringProperty(Function function, String propertyKey) {
Object value = function.getProperty(propertyKey);
return value instanceof String ? (String)value : "";
} | [
"private",
"static",
"String",
"getStringProperty",
"(",
"Function",
"function",
",",
"String",
"propertyKey",
")",
"{",
"Object",
"value",
"=",
"function",
".",
"getProperty",
"(",
"propertyKey",
")",
";",
"return",
"value",
"instanceof",
"String",
"?",
"(",
... | Return a string property of the function
@param function
@param propertyKey
@return | [
"Return",
"a",
"string",
"property",
"of",
"the",
"function"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L417-L420 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.getBooleanProperty | private static boolean getBooleanProperty(Function function, String propertyKey, boolean defaultValue) {
Object value = function.getProperty(propertyKey);
return value instanceof Boolean ? (Boolean)value : defaultValue;
} | java | private static boolean getBooleanProperty(Function function, String propertyKey, boolean defaultValue) {
Object value = function.getProperty(propertyKey);
return value instanceof Boolean ? (Boolean)value : defaultValue;
} | [
"private",
"static",
"boolean",
"getBooleanProperty",
"(",
"Function",
"function",
",",
"String",
"propertyKey",
",",
"boolean",
"defaultValue",
")",
"{",
"Object",
"value",
"=",
"function",
".",
"getProperty",
"(",
"propertyKey",
")",
";",
"return",
"value",
"i... | Return a boolean property of the function
@param function
@param propertyKey
@param defaultValue
@return | [
"Return",
"a",
"boolean",
"property",
"of",
"the",
"function"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L430-L433 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.getAlias | public static String getAlias(Function function) {
String functionAlias = getStringProperty(function,Function.PROP_NAME);
if(!functionAlias.isEmpty()) {
return functionAlias;
}
return function.getClass().getSimpleName();
} | java | public static String getAlias(Function function) {
String functionAlias = getStringProperty(function,Function.PROP_NAME);
if(!functionAlias.isEmpty()) {
return functionAlias;
}
return function.getClass().getSimpleName();
} | [
"public",
"static",
"String",
"getAlias",
"(",
"Function",
"function",
")",
"{",
"String",
"functionAlias",
"=",
"getStringProperty",
"(",
"function",
",",
"Function",
".",
"PROP_NAME",
")",
";",
"if",
"(",
"!",
"functionAlias",
".",
"isEmpty",
"(",
")",
")"... | Return the alias name of the function
@param function Function instance
@return the function ALIAS, name of the function in SQL engine | [
"Return",
"the",
"alias",
"name",
"of",
"the",
"function"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L505-L511 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.