All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geolatte.geom.codec.PostgisWkbV1Dialect Maven / Gradle / Ivy

Go to download

This geoLatte-geom library offers a geometry model that conforms to the OGC Simple Features for SQL specification.

The newest version!
package org.geolatte.geom.codec;

import org.geolatte.geom.*;
import org.geolatte.geom.crs.CoordinateReferenceSystem;

class PostgisWkbV1Dialect extends WkbDialect {

    final public static WkbDialect INSTANCE = new PostgisWkbV1Dialect();

    @Override
    boolean emptyPointAsNaN() {
        return false;
    }

    @Override
    protected 

Long geometryTypeCode(Geometry

geometry) { if (geometry.isEmpty() && geometry.getGeometryType() == GeometryType.POINT) { return (long) WKB_GEOMETRYCOLLECTION; } return super.geometryTypeCode(geometry); } GeometryType parseType(long tpe) { return super.parseType( tpe & 0xFFFF ); } @Override protected

int extraHeaderSize(Geometry

geom) { return geom.getSRID() > 0 ? 4 : 0; //4 bytes for SRID } @Override

BaseWkbVisitor

mkVisitor(Geometry

geom, ByteOrder bo) { return new PostgisWkbVisitor

(mkByteBuffer(geom, bo), this); } static class PostgisWkbVisitor

extends BaseWkbVisitor

{ private boolean hasWrittenSrid = false; PostgisWkbVisitor(ByteBuffer byteBuffer, WkbDialect dialect) { super(byteBuffer, dialect); } protected void writeTypeCodeAndSrid(Geometry

geometry, ByteBuffer output) { long typeCode = dialect().geometryTypeCode(geometry); boolean hasSrid = (geometry.getSRID() > 0); CoordinateReferenceSystem

crs = geometry.getCoordinateReferenceSystem(); if (hasSrid && !hasWrittenSrid) { typeCode |= PostgisWkbTypeMasks.SRID_FLAG; } if (geometry.hasM()) { typeCode |= PostgisWkbTypeMasks.M_FLAG; } if (geometry.hasZ()) { typeCode |= PostgisWkbTypeMasks.Z_FLAG; } output.putUInt(typeCode); if (hasSrid && !hasWrittenSrid) { output.putInt(geometry.getSRID()); hasWrittenSrid = true; } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy