On Wed, Apr 25, 2007 at 01:31:15PM +0200, Hakan Tandogan wrote:
> 
> > Selam,
> >
> >
> > Bana bu sekilde yapmak coastline_import.pl'den daha pratik ve
> > temiz geldi. Program topluluk icine cikacak kadar duzgun yazilmis
> > degil ama denemek isteyen varsa seve seve paylasirim. 'shapelib'
> > kullaniyor, kucuk bir C programi (sadece Linux'ta denedim). Butun
> > Ortadogu shp dosyasini gpx ya da osm'e cevirmek 30 saniyenin
> 
> Bütün Ortagu dosyasi dedigin "NGA_GlobalShoreline_cd10" dosyami?

evet.

> > altinda suruyor, JOSM'u ve OSM sunucusunu mutsuz etmemek icin
> > kucuk kucuk calismakta yarar var ama. Urettigi sonuc su anda
> 
> coast_import en gec her 80 node'de bir yeni bir way olusturuyor,
> böylece JOSMu fazla mutsuz etmiyor. Gördügüm yollar cogunlukla bir
> level-12 karesinin icine sigmakta.

Benim porgram da parcaliyor segmentlere, ama butun Turkiye
kiyilarini birden yukleyince JOSM bellek bulmakta zorlaniyor
benim makinada :)

> 
> > sanirim coastline_export'tan daha iyi, ama pgs verilerinden
> > kaynakli bir gurup sorun var (ornegin denizin sag tarafta
> > kalmasini garantilemenin bir yolu yok). biraz ugrastiktan sonra
> > sonuclara  guvenirsem, dogrudan sisteme yukleme secenegini de
> > ekleyebilirim.
> >
> >> Ilk önce Antalya kiyisini denemek istiyorum (orasi Istanbul kadar
> >> karmasik degil). Ilk önce bu programla bütün kiyilari ekleyip sonra
> >> elimizde veri olan yerleri düzeltsek olurmu?
> >
> > Benim simdilik Marmara denizine bir el atasim var, olasi kucuk
> > sorunlari cozdukten sonra belki otomatik butun TR kiyilarini
> > ekleriz, ama bir sekilde uzerinden gecmis oldugumuz yerleri
> > isaretlesek iyi olacak..
> >
> > Ben bu aksam bir Marmara'ya el atip sonuclari yazarim..
> 
> O zaman ben Akdeniz kiyilarina baslamisken lat 37'den asagiya dogru olan
> kisimi bitireyim, sende Marmarayi dene. Senin program daha iyi sonuca
> varirisa coast_import'la ekledigim kisimlari silip tekrar senin programla
> ekleriz.

Anlastik. Ben Marmara'dan baslayip iki yone yavas yavas
ilerlemeyi dusunuyorum. Eger dusundugum gibi calisirsa, bu aksam
belki Karadeniz ve Izmir'e kadar ege sahilini de yukleyebilirim.
Yaklasinca tekrar listeye yazarim, ayni yerleri ust uste
yapmayalim.

Benim program ayni veriyi uretiyor, eksik/baglantisiz segment
konusunda biraz daha iyi su anda. programin su andaki kullandigim
hali ekte. aksam biraz daha toparlayacagim..

selamlar,
-- 
cagri

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <shapefil.h>


int main(int argc, char **argv)
{
    SHPHandle   hSHP;
    int nShapeType, nEntities, i, iPart;
    const char  *pszPlus;
    double  adfMinBound[4], adfMaxBound[4];
    double      lonMin=-90.0, lonMax=90.0, latMin=-180.0, latMax=180.0;
    unsigned long   node_count=1; 
    unsigned long   start_node=1; 
    unsigned long   pTotal=0;
    unsigned long   way_start=1;
    unsigned long   way_count=0;
    int         output_osm = 0;
    int         k;
    int         c;
    int         max_nodes=100;
/*    double      prevLat=0.0, prevLon=0.0; */

    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"output-format", required_argument, 0, 'f'},
            {"max-nodes", required_argument, 0, 's'},
            {"minlat", required_argument, 0, 'p'},
            {"maxlat", required_argument, 0, 'P'},
            {"minlon", required_argument, 0, 'm'},
            {"maxlon", required_argument, 0, 'M'},
            {"osm", no_argument, 0, 'o'},
            {0, 0, 0, 0}
        };

        c = getopt_long (argc, argv, "of:m:M:p:P:s:",
                 long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 'f':
            if(!strncmp("osm",optarg, 3)){
                output_osm = 1;
            }
            break;
        case 'o':
            output_osm = 1;
            break;

        case 'p':
            latMin = strtod(optarg, NULL);
            break;
        case 'P':
            latMax = strtod(optarg, NULL);
            break;
        case 'm':
            lonMin = strtod(optarg, NULL);
            break;
        case 'M':
            lonMax = strtod(optarg, NULL);
            break;
        case 's':
            max_nodes = strtol(optarg, NULL, 0);
            break;
        default:
            printf ("?? getopt returned character code 0%o ??\n", c);
        }
    }

    if ((argc - optind) != 1) {
        fprintf(stderr,"%s [options] shp_file\n"
                "Options are:\n"
                " -m --minlon        -180..180 min merdian [-180]\n"
                " -M --maxlon        -180..180 max maridian [180]\n"
                " -p --minlat        -90..90 min parallel [-90]\n"
                " -P --maxlat        -90..90 max parallel [90]\n"
                " -f --output-format osm or gpx [gpx]\n"
                " -m --max-nodes  max nodes per way/trkseg [100]\n"
                "                    0 for one way/trkseg per shape\n",
                argv[0]);
        return -1;
    }

    hSHP = SHPOpen(argv[optind], "rb");

    if(hSHP == NULL){
        fprintf(stderr, "Unable to open:%s\n", argv[1] );
        return -1;
    }

    SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound );

    fprintf(stderr, "Shapefile Type: %s   # of Shapes: %d\n\n",
            SHPTypeName( nShapeType ), nEntities );
    
    fprintf(stderr, "File Bounds: (%12.3f,%12.3f,%g,%g)\n"
                    "         to  (%12.3f,%12.3f,%g,%g)\n",
            adfMinBound[0], adfMinBound[1], adfMinBound[2], adfMinBound[3], 
            adfMaxBound[0], adfMaxBound[1], adfMaxBound[2], adfMaxBound[3] );
    

    if(output_osm){
        printf("<?xml version='1.0' encoding='UTF-8'?>\n"
               "<osm version='0.3' generator='shp2osm'>\n");
    } else {
        printf("<gpx version='1.1' creator='shpt2trk'"
           "xmlns='http://www.topografix.com/GPX/1/1'>\n");
        printf("\t<trk>\n");
        printf("\t\t<trkseg>\n");
    }

    start_node = 1;

    for( i = 0; i < nEntities; i++ ) {
        int j;
        int nVertices;
        SHPObject   *psShape;

        psShape = SHPReadObject( hSHP, i );

        nVertices = psShape->nVertices;
        if((psShape->padfX[0] == psShape->padfX[psShape->nVertices-1]) &&
           (psShape->padfY[0] == psShape->padfY[psShape->nVertices-1])) {
           nVertices = psShape->nVertices - 1;
        }
        for( j = 0, iPart = 1; j < nVertices; j++ ) {
            const char  *pszPartType = "";

            if(j == 0 && psShape->nParts > 0)
                pszPartType = SHPPartTypeName( psShape->panPartType[0]);
            
            if(iPart < psShape->nParts && psShape->panPartStart[iPart] == j){
                pszPartType = SHPPartTypeName( psShape->panPartType[iPart] );
                iPart++;
                pszPlus = "+";
            } else
                pszPlus = " ";


            if((psShape->padfX[j] >= lonMin) && 
               (psShape->padfX[j] <= lonMax) &&
               (psShape->padfY[j] >= latMin) && 
               (psShape->padfY[j] <= latMax)) {
                 if(output_osm){
/*
                    if((psShape->padfX[j] == prevLat) &&
                       (psShape->padfY[j] == prevLon)) {
                        fprintf(stderr,"\nfound duplicate!\n");
                    }
                    prevLat = psShape->padfX[j];
                    prevLon = psShape->padfY[j];
 */
                    printf("\t<node id='-%lu' lon='%f' lat='%f'>\n",
                        node_count,
                        psShape->padfX[j],
                        psShape->padfY[j]);
                    printf("\t\t<tag k='source' v='PGS' />\n"
                           "\t\t<tag k='created_by' v='shp2osm' />\n"
                           "\t</node>\n");
                    if(j != 0){
                        printf("\t<segment id='-%lu' "
                               "from='-%lu' to='-%lu'>\n",
                               node_count-1, node_count-1, node_count);
                        printf("\t\t<tag k='source' v='PGS' />\n"
                               "\t\t<tag k='created_by' v='shp2osm' />\n"
                               "\t</segment>\n");
                    }
                } else {
                    printf("\t\t\t<trkpt lon='%f' lat='%f' />\n",
                        psShape->padfX[j],
                        psShape->padfY[j]);
                }
                 node_count++;
                 if(max_nodes && (!(node_count % (max_nodes+1)))){
                    if(output_osm){
                        printf("\t<way id='-%lu'>\n", ++way_count);
                        for(k=way_start; k < node_count-1; k++){
                            printf("\t\t<seg id='-%u' />\n", k);
                        }
                        printf("\t\t<tag k='source' v='PGS' />\n"
                               "\t\t<tag k='created_by' v='shp2osm' />\n"
                               "\t\t<tag k='natural' v='coastline' />\n"
                               "\t</way>\n");
                        way_start = node_count-1;
                    } else {
                        printf("\t\t</trkseg>\n\t\t<trkseg>\n");
                    }
                    start_node = node_count;
                 }
            }
            pTotal++;
        }
        if(start_node != node_count){
            if(output_osm) {
                int max_segnum = node_count -1;
                if(psShape->nVertices != nVertices) {
                        printf("\t<segment id='-%lu' "
                               "from='-%lu' to='-%lu'>\n",
                               node_count, node_count, way_start);
                        printf("\t\t<tag k='source' v='PGS' />\n"
                               "\t\t<tag k='created_by' v='shp2osm' />\n"
                               "\t</segment>\n");
                        max_segnum=node_count;
                }
                printf("\t<way id='-%lu'>\n", ++way_count);
                for(k=way_start; k < max_segnum; k++){
                    printf("\t\t<seg id='-%u' />\n", k);
                }
                printf("\t\t<tag k='source' v='PGS' />\n"
                       "\t\t<tag k='created_by' v='shp2osm' />\n"
                       "\t\t<tag k='natural' v='coastline' />\n"
                       "\t</way>\n");
                way_start = node_count;
            } else {
                printf("\t\t</trkseg>\n\t\t<trkseg>\n");
            }
            start_node = node_count;
        }
        SHPDestroyObject( psShape );

        fprintf(stderr, "Processed %06lu/%06lu points,"
                        " in %04d/%04d shapes            \r",
                        node_count, pTotal, i, nEntities );
    }
    if(output_osm){
        printf("</osm>\n");
    } else {
        printf("\t\t</trkseg>\n\t</trk>\n</gpx>");
    }

    SHPClose( hSHP );

    fprintf(stderr,"\n");
    return 0;
}
_______________________________________________
Talk-tr mailing list
[email protected]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk-tr

Cevap