ayushtkn commented on code in PR #6581: URL: https://github.com/apache/hive/pull/6581#discussion_r3653198869
########## ql/src/java/org/apache/hadoop/hive/ql/udf/esri/EsriShapeConverter.java: ########## @@ -0,0 +1,742 @@ +/* + * 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 org.locationtech.jts.algorithm.Orientation; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.CoordinateXYM; +import org.locationtech.jts.geom.CoordinateXYZM; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryCollection; +import org.locationtech.jts.geom.LinearRing; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.MultiLineString; +import org.locationtech.jts.geom.MultiPoint; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.Polygon; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.List; + +/** + * Reads and writes raw ESRI shape binary format directly from/to JTS geometries, + * without any dependency on the ESRI Geometry library. + * + * <p>All binary values are little-endian as per the ESRI shape format specification + * (ESRI Shapefile Technical Description, July 1998, + * <a href="https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf"> + * shapefile.pdf</a>). + * + * <p>Supported shape types on read: + * <ul> + * <li>0 - Null/Unknown</li> + * <li>1 - Point</li> + * <li>3 - Polyline (paths)</li> + * <li>5 - Polygon (rings)</li> + * <li>8 - MultiPoint</li> + * <li>11 - PointZ (optionally with M)</li> + * <li>13 - PolylineZ (optionally with M)</li> + * <li>15 - PolygonZ (optionally with M)</li> + * <li>18 - MultiPointZ (optionally with M)</li> + * <li>21 - PointM</li> + * <li>23 - PolylineM</li> + * <li>25 - PolygonM</li> + * <li>28 - MultiPointM</li> + * </ul> + * + * <p>The M-bearing types are read (to stay compatible with data serialized by the + * previous ESRI-library implementation) but never written; {@link #toEsriShape} emits + * only the XY and XYZ types. + */ +public final class EsriShapeConverter { + + private static final int TYPE_NULL = 0; + private static final int TYPE_POINT = 1; + private static final int TYPE_POLYLINE = 3; + private static final int TYPE_POLYGON = 5; + private static final int TYPE_MULTIPOINT = 8; + private static final int TYPE_POINT_Z = 11; + private static final int TYPE_POLYLINE_Z = 13; + private static final int TYPE_POLYGON_Z = 15; + private static final int TYPE_MULTIPOINT_Z = 18; + private static final int TYPE_POINT_M = 21; + private static final int TYPE_POLYLINE_M = 23; + private static final int TYPE_POLYGON_M = 25; + private static final int TYPE_MULTIPOINT_M = 28; + + // ESRI marks an absent measure with any value less than this sentinel. Review Comment: <= is correct on read — kept it. Exactly -1e38 is the no-data marker written by ArcView/GDAL and others, and a real measure is never exactly -1e38, so <= catches that marker as well as any value below it. The only actual bug was on the write side: absent M was written as -1e38, which a strict-< reader (e.g. ESRI's own Interop.translateFromAVNaN) would read back as a valid measure. Changed the write value to -Double.MAX_VALUE (matching ESRI's translateToAVNaN), which every reader interprets as no-data. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
