Package gps.garmin.img.structure.data

Examples of gps.garmin.img.structure.data.SubfileTRE


   
    protected void parseTRESubfile() throws ParseException {
        FATBlock treFatBlock = fatBlocks.get(SubfileType.TRE);
        seek(treFatBlock.getSubfileOffset());

        SubfileTRE subfile =
            (SubfileTRE) parseSubfileCommonHeader(treFatBlock.getSubfileOffset());
        SubfileHeaderTRE treHeader = subfile.getHeader();

        // North boundary
        treHeader.setNorthBoundary(Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

        // East boundary
        treHeader.setEastBoundary(Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

        // South boundary
        treHeader.setSouthBoundary(Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

        // West boundary
        treHeader.setWestBoundary(Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

        // Map levels section offset
        treHeader.setMapLevelsSectionOffset(getLittleEndianWord(4));

        // Map levels section size
        treHeader.setMapLevelsSectionSize(getLittleEndianWord(4));

        // Subdivisions section offset
        treHeader.setSubdivisionsSectionOffset(getLittleEndianWord(4));

        // Subdivisions section size
        treHeader.setSubdivisionsSectionSize(getLittleEndianWord(4));

        // Copyright section offset
        treHeader.setCopyrightSectionOffset(getLittleEndianWord(4));

        // Copyright section size
        treHeader.setCopyrightSectionSize(getLittleEndianWord(4));

        // Copyright record size
        treHeader.setCopyrightRecordSize(getLittleEndianWord(2));

        // 0x00 x4
        skipBytes(4);

        // POI display flags
        nextByte();
        treHeader.setTransparentMap((currentByte & 1) == 1);
        treHeader.setShowStreetBeforeStreetNumber((currentByte & 2) == 2);
        treHeader.setShowZipBeforeCity((currentByte & 4) == 4);

        skipBytes(3);
        skipBytes(4);

        // 0x0001
        skipBytes(2);

        // 0x00
        skipBytes(1);

        // Polyline overview section offset
        treHeader.setPolylineOverviewSectionOffset(getLittleEndianWord(4));

        // Polyline overview section length
        treHeader.setPolylineOverviewSectionLength(getLittleEndianWord(4));

        // Polyline overview records size
        treHeader.setPolylineOverviewRecordsSize(getLittleEndianWord(2));

        skipBytes(2);

        // 0x0000
        skipBytes(2);

        // Polygon overview section offset
        treHeader.setPolygonOverviewSectionOffset(getLittleEndianWord(4));

        // Polygon overview section length
        treHeader.setPolygonOverviewSectionLength(getLittleEndianWord(4));

        // Polygon overview records size
        treHeader.setPolygonOverviewRecordsSize(getLittleEndianWord(2));

        skipBytes(2);

        // 0x0000
        skipBytes(2);

        // Point overview section offset
        treHeader.setPointOverviewSectionOffset(getLittleEndianWord(4));

        // Point overview section length
        treHeader.setPointOverviewSectionLength(getLittleEndianWord(4));

        // Point overview records size
        treHeader.setPointOverviewRecordsSize(getLittleEndianWord(2));

        skipBytes(2);

        // 0x0000
        skipBytes(2);

        // Header longer than 116 bytes
        if (subfile.getCommonHeader().getHeadersLength() > SubfileHeaderTRE.LENGTH_116) {
            // Map ID
            treHeader.setMapID(String.valueOf(getLittleEndianWord(4)));

            // Header longer than 120 bytes
            if (subfile.getCommonHeader().getHeadersLength() > SubfileHeaderTRE.LENGTH_120) {
                // 0x00000000
                skipBytes(4);

                // TRE7 section offset
                treHeader.setTre7SectionOffset(getLittleEndianWord(4));

                // TRE7 section length
                treHeader.setTre7SectionLength(getLittleEndianWord(4));

                // TRE7 records size
                treHeader.setTre7RecordsSize(getLittleEndianWord(2));

                skipBytes(4);

                // TRE8 section offset
                treHeader.setTre8SectionOffset(getLittleEndianWord(4));

                // TRE8 secion length
                treHeader.setTre8SectionLength(getLittleEndianWord(4));

                skipBytes(4);

                // 0x0000
                skipBytes(4);

                // Header longer than 154 bytes
                if (subfile.getCommonHeader().getHeadersLength() > SubfileHeaderTRE.LENGTH_154) {
                    // Map level encryption key
                    treHeader.setMapLevelsSectionEncryptionKey(parseString(20));

                    // TRE9 section offset
                    treHeader.setTre9SectionOffset(getLittleEndianWord(4));

                    // TRE9 section length
                    treHeader.setTre9SectionLength(getLittleEndianWord(4));

                    // TRE9 records size
                    treHeader.setTre9RecordsSize(getLittleEndianWord(2));

                    // 0x00000000
                    skipBytes(4);
                }
            }
        }

        // Map descriptor
        String mapDescriptor = "";
        nextByte();
        while (currentByte != 0) {
            mapDescriptor += (char) currentByte;
            nextByte();
        }
        treHeader.setMapDescriptor(mapDescriptor);

        // Copyright section
        seek(treFatBlock.getSubfileOffset() + treHeader.getCopyrightSectionOffset());
        int numberOfRecords =
            treHeader.getCopyrightSectionSize() / treHeader.getCopyrightRecordSize();
        for (int i = 0; i < numberOfRecords; i++) {
            subfile.getCopyrights().add(getLittleEndianWord(treHeader.getCopyrightRecordSize()));
        }
       
        // Map levels section
        seek(treFatBlock.getSubfileOffset() + treHeader.getMapLevelsSectionOffset());
        int numberOfLevels = treHeader.getMapLevelsSectionSize() / 4// fixme, porque 4?
        for (int i = 0; i < numberOfLevels; i++) {
            MapLevel mapLevel = new MapLevel();
            mapLevel.setNumber(numberOfLevels - i - 1);

            // Inherited
            nextByte();
            mapLevel.setInherited((currentByte & 128) == 128);
            // Zoom level
            mapLevel.setZoomLevel(currentByte & 15);

            // Bits per coord
            mapLevel.setBitsPerCoordinate(nextByte());

            // Subdivisions
            mapLevel.setQuantityOfSubdivisions(getLittleEndianWord(2));

            subfile.getMapLevels().add(mapLevel);
        }

        // Subdivisions section
        seek(treFatBlock.getSubfileOffset() + treHeader.getSubdivisionsSectionOffset());
        boolean firstSubdivision = true;
        int subdivisionCounter = 1;
        Subdivision contiguousPreviousSubdivision = null;
        Collection<Subdivision> subdivisionsTemp = new ArrayList<Subdivision>();
        for (MapLevel mapLevel : subfile.getMapLevels()) {
            for (int i = 0; i < mapLevel.getQuantityOfSubdivisions(); i++) {
                Subdivision subdivision = new Subdivision();
                subdivision.setLevel(mapLevel);
                subdivision.setNumber(subdivisionCounter++);

                // Offset in RGN subfile
                subdivision.setOffsetInRGNSubfile(getLittleEndianWord(3));

                // Object types
                subdivision.setObjectTypes(getTRESubfileObjectTypes());

                // Longitude center
                subdivision.setLongitudeCenter(
                    Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

                // Latitude center
                subdivision.setLatitudeCenter(
                    Utils.convertMapUnitsToDegrees(getSignedInteger(3)));

                // Width
                int value = getLittleEndianWord(2);
                subdivision.setWidth(value & 32767);
                subdivision.setTotalWidth((subdivision.getWidth() * 2) + 1);

                subdivision.setTerminatingFlag((value & 32768) == 32768);
                if (contiguousPreviousSubdivision != null) {
                    contiguousPreviousSubdivision.setContiguousSubdivision(subdivision);
                }
                if (subdivision.isTerminatingFlag()) {
                    contiguousPreviousSubdivision = null;
                } else {
                    contiguousPreviousSubdivision = subdivision;
                }

                // Height
                subdivision.setHeight(getLittleEndianWord(2));
                subdivision.setTotalHeight((subdivision.getHeight() * 2) + 1);

                if (mapLevel.getNumber() != 0) {
                    // Next level subdivision
                    int nextSubdivisionNumber = getLittleEndianWord(2);
                    if (nextSubdivisionNumber != 0) {
                        Subdivision subdivisionTemp = new Subdivision();
                        subdivisionTemp.setNumber(nextSubdivisionNumber);
                        subdivision.setNextLevelSubdivision(subdivisionTemp);
                    }
                }

                if (firstSubdivision) {
                    subfile.setFirstSubdivision(subdivision);
                    firstSubdivision = false;
                }

                for (Subdivision subdivisionTemp : subdivisionsTemp) {
                    if (subdivisionTemp.getNextLevelSubdivision() != null) {
                        if (subdivisionTemp.getNextLevelSubdivision().getNumber() == subdivision.getNumber()) {
                            subdivisionTemp.setNextLevelSubdivision(subdivision);
                        }
                    }
                }
                subdivisionsTemp.add(subdivision);
            }
        }

        // Polyline section
        seek(treFatBlock.getSubfileOffset() + treHeader.getPolylineOverviewSectionOffset());
        int numberOfPolylines =
            treHeader.getPolylineOverviewSectionLength() /
            treHeader.getPolylineOverviewRecordsSize();
        for (int i = 0; i < numberOfPolylines; i++) {
            Polyline polyline = new Polyline();
            polyline.setNumber(i + 1);

            // Polyline type
            nextByte()// fixme, siempre es por default? no se usa el byte?
            polyline.setType(PolylineType.DEFAULT);

            // Maximum level
            polyline.setMaximumLevelWherePresent(nextByte());

            if (treHeader.getPolylineOverviewRecordsSize() == 3) {
                skipBytes(1);
            }

            subfile.getPolylines().add(polyline);
        }

        // Polygon section
        seek(treFatBlock.getSubfileOffset() + treHeader.getPolygonOverviewSectionOffset());
        int numberOfPolygons =
            treHeader.getPolygonOverviewSectionLength() /
            treHeader.getPolygonOverviewRecordsSize();
        for (int i = 0; i < numberOfPolygons; i++) {
            Polygon polygon = new Polygon();
            polygon.setNumber(i + 1);

            // Polygon type
            nextByte()// fixme, siempre es por default? no se usa el byte?
            polygon.setType(PolygonType.DEFAULT);

            // Maximum level
            polygon.setMaximumLevelWherePresent(nextByte());

            if (treHeader.getPolygonOverviewRecordsSize() == 3) {
                skipBytes(1);
            }

            subfile.getPolygons().add(polygon);
        }

        // Point section
        seek(treFatBlock.getSubfileOffset() + treHeader.getPointOverviewSectionOffset());
        int numberOfPoints =
            treHeader.getPointOverviewSectionLength() /
            treHeader.getPointOverviewRecordsSize();
        for (int i = 0; i < numberOfPoints; i++) {
            Point point = new Point();
            point.setNumber(i + 1);

            // Point type
            nextByte()// fixme, siempre es por default? no se usa el byte?
            point.setType(PointType.DEFAULT);

            // Maximum level
            point.setMaximumLevelWherePresent(nextByte());

            // Point subtype
            nextByte()// fixme, siempre es por default? no se usa el byte?
            point.setSubtype(PointSubtype.DEFAULT);

            subfile.getPoints().add(point);
        }
       
        img.getSubfiles().add(subfile);
    }
View Full Code Here


        // Subfile type
        commonHeader.setType(SubfileType.getType(parseString(10)));
        switch (commonHeader.getType()) {
            case RGN: subfile = new SubfileRGN(); break;
            case TRE: subfile = new SubfileTRE(); break;
            case LBL: subfile = new SubfileLBL(); break;
            case NOD: subfile = new SubfileNOD(); break;
            case NET: subfile = new SubfileNET(); break;
            case MDR: subfile = new SubfileMDR(); break;
            default: subfile = new SubfileNone(); break;
View Full Code Here

                System.out.println("        Subfile type " + subfile.getCommonHeader().getType());
                System.out.println("          Headers length " + subfile.getCommonHeader().getHeadersLength());
                System.out.println("          Offset " + subfile.getOffset());
                switch (subfile.getCommonHeader().getType()) {
                    case TRE:
                        SubfileTRE treSubfile = (SubfileTRE) subfile;
                        System.out.println("          North boundary " + treSubfile.getHeader().getNorthBoundary());
                        System.out.println("          East boundary " + treSubfile.getHeader().getEastBoundary());
                        System.out.println("          South boundary " + treSubfile.getHeader().getSouthBoundary());
                        System.out.println("          West boundary " + treSubfile.getHeader().getWestBoundary());
                        System.out.println("          Map levels section offset " + treSubfile.getHeader().getMapLevelsSectionOffset());
                        System.out.println("          Map levels section size " + treSubfile.getHeader().getMapLevelsSectionSize());
                        System.out.println("          Subdivisions section offset " + treSubfile.getHeader().getSubdivisionsSectionOffset());
                        System.out.println("          Subdivisions section size " + treSubfile.getHeader().getSubdivisionsSectionSize());
                        System.out.println("          Copyright section offset " + treSubfile.getHeader().getCopyrightSectionOffset());
                        System.out.println("          Copyright section size " + treSubfile.getHeader().getCopyrightSectionSize());
                        System.out.println("          Copyright record size " + treSubfile.getHeader().getCopyrightRecordSize());
                        System.out.println("          Transparent map " + treSubfile.getHeader().isTransparentMap());
                        System.out.println("          Show street before street number " + treSubfile.getHeader().isShowStreetBeforeStreetNumber());
                        System.out.println("          Show zip before city " + treSubfile.getHeader().isShowZipBeforeCity());
                        System.out.println("          Polyline section offset " + treSubfile.getHeader().getPolylineOverviewSectionOffset());
                        System.out.println("          Polyline section length " + treSubfile.getHeader().getPolylineOverviewSectionLength());
                        System.out.println("          Polyline records size " + treSubfile.getHeader().getPolylineOverviewRecordsSize());
                        System.out.println("          Polygon section offset " + treSubfile.getHeader().getPolygonOverviewSectionOffset());
                        System.out.println("          Polygon section length " + treSubfile.getHeader().getPolygonOverviewSectionLength());
                        System.out.println("          Polygon records size " + treSubfile.getHeader().getPolygonOverviewRecordsSize());
                        System.out.println("          Point section offset " + treSubfile.getHeader().getPointOverviewSectionOffset());
                        System.out.println("          Point section length " + treSubfile.getHeader().getPointOverviewSectionLength());
                        System.out.println("          Point records size " + treSubfile.getHeader().getPointOverviewRecordsSize());
                        System.out.println("          Map id " + treSubfile.getHeader().getMapID());
                        System.out.println("          TRE7 section offset " + treSubfile.getHeader().getTre7SectionOffset());
                        System.out.println("          TRE7 section length " + treSubfile.getHeader().getTre7SectionLength());
                        System.out.println("          TRE7 records size " + treSubfile.getHeader().getTre7RecordsSize());
                        System.out.println("          TRE8 section offset " + treSubfile.getHeader().getTre8SectionOffset());
                        System.out.println("          TRE8 section length " + treSubfile.getHeader().getTre8SectionLength());
                        System.out.println("          Map level encryption key " + treSubfile.getHeader().getMapLevelsSectionEncryptionKey());
                        System.out.println("          TRE9 section offset " + treSubfile.getHeader().getTre9SectionOffset());
                        System.out.println("          TRE9 section length " + treSubfile.getHeader().getTre9SectionLength());
                        System.out.println("          TRE9 records size " + treSubfile.getHeader().getTre9RecordsSize());

                        for (int copyright : treSubfile.getCopyrights()) {
                            System.out.println("              Copyright " + copyright);
                        }
                       
                        for (MapLevel level : treSubfile.getMapLevels()) {
                            System.out.println("              Map level " + level.getNumber());
                            System.out.println("              Inherited " + level.isInherited());
                            System.out.println("              Zoom level " + level.getZoomLevel());
                            System.out.println("              Bits per coord " + level.getBitsPerCoordinate());
                            System.out.println("              Subdivisions " + level.getQuantityOfSubdivisions());
                        }
                        System.out.println("");
                       
                        if (treSubfile.getFirstSubdivision() != null) {
                            showSubdivision(treSubfile.getFirstSubdivision());
                        }
                        System.out.println("");
                       
                        for (Polyline polyline : treSubfile.getPolylines()) {
                            System.out.println("              Polyline number " + polyline.getNumber());
                            System.out.println("              Polyline type " + polyline.getType());
                            System.out.println("              Polyline maximum level " + polyline.getMaximumLevelWherePresent());
                        }
                        System.out.println("");

                        for (Polygon polygon : treSubfile.getPolygons()) {
                            System.out.println("              Polygon number " + polygon.getNumber());
                            System.out.println("              Polygon type " + polygon.getType());
                            System.out.println("              Polygon maximum level " + polygon.getMaximumLevelWherePresent());
                        }
                        System.out.println("");

                        for (Point point : treSubfile.getPoints()) {
                            System.out.println("              Point number " + point.getNumber());
                            System.out.println("              Point type " + point.getType());
                            System.out.println("              Point subtype " + point.getSubtype());
                            System.out.println("              Point maximum level " + point.getMaximumLevelWherePresent());
                        }
View Full Code Here

            xorByte.setText("0x" + Integer.toHexString(header.getXorByte()));
           
            for (Subfile subfile : img.getSubfiles()) {
                switch (subfile.getCommonHeader().getType()) {
                    case TRE:
                        SubfileTRE treSubfile = (SubfileTRE) subfile;

                        addSubdivision(rootNode, treSubfile.getFirstSubdivision());
                       
                        //showSubdivision();
                        break;
                }
            }
View Full Code Here

TOP

Related Classes of gps.garmin.img.structure.data.SubfileTRE

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.