Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hive.ql.udf.esri;
import com.esri.core.geometry.ogc.OGCGeometry;
import com.esri.core.geometry.ogc.OGCLineString;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.io.BooleanWritable;
import org.apache.hadoop.io.BytesWritable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Description(name = "ST_IsRing",
value = "_FUNC_(ST_LineString) - return true if the linestring is closed & simple",
extended = "Example:\n" + " SELECT _FUNC_(ST_LineString(0.,0., 3.,4., 0.,4., 0.,0.)) FROM src LIMIT 1; -- true\n"
+ " SELECT _FUNC_(ST_LineString(0.,0., 1.,1., 1.,2., 2.,1., 1.,1., 0.,0.)) FROM src LIMIT 1; -- false\n"
+ " SELECT _FUNC_(ST_LineString(0.,0., 3.,4.)) FROM src LIMIT 1; -- false\n")
//@HivePdkUnitTests(
// cases = {
// @HivePdkUnitTest(
// query = "select ST_IsRing(ST_LineString(0.,0., 3.,4., 0.,4., 0.,0.)) from onerow",
// result = "true"
// ),
// @HivePdkUnitTest(
// query = "select ST_IsRing(ST_LineString(0.,0., 3.,4.)) from onerow",
// result = "false"
// ),
// @HivePdkUnitTest(
// query = "select ST_IsRing(ST_LineString(0.,0., 1.,1., 1.,2., 2.,1., 1.,1., 0.,0.)) from onerow",
// result = "false"
// ),
// @HivePdkUnitTest(
// query = "select ST_IsRing(null) from onerow",
// result = "null"
// )
// }
// )
public class ST_IsRing extends ST_GeometryAccessor {
final BooleanWritable resultBoolean = new BooleanWritable();
static final Logger LOG = LoggerFactory.getLogger(ST_IsRing.class.getName());
public BooleanWritable evaluate(BytesWritable geomref) {
if (geomref == null || geomref.getLength() == 0) {
LogUtils.Log_ArgumentsNull(LOG);
return null;
}
OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
if (ogcGeometry == null) {
LogUtils.Log_ArgumentsNull(LOG);
return null;
}
try {
switch (GeometryUtils.getType(geomref)) {
case ST_LINESTRING:
OGCLineString lns = (OGCLineString) ogcGeometry;
resultBoolean.set(lns.isClosed() && lns.isSimple());
return resultBoolean;
default: // ST_IsRing gives ERROR on Point, Polygon, or MultiLineString - on Postgres
LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.getType(geomref));
return null;
}
} catch (Exception e) {
LogUtils.Log_InternalError(LOG, "ST_IsRing" + e);
return null;
}
}
}