コード例 #1
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
PJ *proj_create_argv (PJ_CONTEXT *ctx, int argc, char **argv) {
/**************************************************************************************
Create a new PJ object in the context ctx, using the given definition argument
array argv. If ctx==0, the default context is used, if definition==0, or invalid,
a null-pointer is returned. The definition arguments may use '+' as argument start
indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm",
"zone=32"}.
**************************************************************************************/
    PJ *P;
    const char *c;

    if (0==argv)
        return 0;
    if (0==ctx)
        ctx = pj_get_default_ctx ();

    /* We assume that free format is used, and build a full proj_create compatible string */
    c = pj_make_args (argc, argv);
    if (0==c)
        return 0;

    P = proj_create (ctx, c);

    pj_dealloc ((char *) c);
    return P;
}
コード例 #2
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
PJ_INIT_INFO proj_init_info(const char *initname){
/******************************************************************************
    Information about a named init file.

    Maximum length of initname is 64.

    Returns PJ_INIT_INFO struct.

    If the init file is not found all members of the return struct are set
    to the empty string.

    If the init file is found, but the metadata is missing, the value is
    set to "Unknown".
******************************************************************************/
    int file_found;
    char param[80], key[74];
    paralist *start, *next;
    PJ_INIT_INFO ininfo;
    PJ_CONTEXT *ctx = pj_get_default_ctx();

    memset(&ininfo, 0, sizeof(PJ_INIT_INFO));

    file_found = pj_find_file(ctx, initname, ininfo.filename, sizeof(ininfo.filename));
    if (!file_found || strlen(initname) > 64) {
        return ininfo;
    }

    /* The initial memset (0) makes strncpy safe here */
    strncpy (ininfo.name, initname, sizeof(ininfo.name) - 1);
    strcpy(ininfo.origin, "Unknown");
    strcpy(ininfo.version, "Unknown");
    strcpy(ininfo.lastupdate, "Unknown");

    strncpy (key, initname, 64); /* make room for ":metadata\0" at the end */
    key[64] = 0;
    strncat(key, ":metadata", 9);
    strcpy(param, "+init=");
    /* The +strlen(param) avoids a cppcheck false positive warning */
    strncat(param + strlen(param), key, sizeof(param)-1-strlen(param));

    start = pj_mkparam(param);
    pj_expand_init(ctx, start);

    if (pj_param(ctx, start, "tversion").i)
        strncpy(ininfo.version, pj_param(ctx, start, "sversion").s, sizeof(ininfo.version) - 1);

    if (pj_param(ctx, start, "torigin").i)
        strncpy(ininfo.origin, pj_param(ctx, start, "sorigin").s, sizeof(ininfo.origin) - 1);

    if (pj_param(ctx, start, "tlastupdate").i)
        strncpy(ininfo.lastupdate, pj_param(ctx, start, "slastupdate").s, sizeof(ininfo.lastupdate) - 1);

    for ( ; start; start = next) {
        next = start->next;
        pj_dalloc(start);
    }

   return ininfo;
}
コード例 #3
0
ファイル: geod_set.c プロジェクト: BJangeofan/proj.4
	void
geod_set(int argc, char **argv) {
	paralist *start = 0, *curr;
	double es;
	char *name;
	int i;

    /* put arguments into internal linked list */
	if (argc <= 0)
		emess(1, "no arguments in initialization list");
	start = curr = pj_mkparam(argv[0]);
	for (i = 1; i < argc; ++i) {
		curr->next = pj_mkparam(argv[i]);
		curr = curr->next;
	}
	/* set elliptical parameters */
	if (pj_ell_set(pj_get_default_ctx(),start, &geod_a, &es)) emess(1,"ellipse setup failure");
	/* set units */
	if ((name = pj_param(NULL,start, "sunits").s) != NULL) {
		char *s;
                struct PJ_UNITS *unit_list = pj_get_units_ref();
		for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ;
		if (!s)
			emess(1,"%s unknown unit conversion id", name);
		fr_meter = 1. / (to_meter = atof(unit_list[i].to_meter));
	} else
		to_meter = fr_meter = 1.;
	geod_f = es/(1 + sqrt(1 - es));
	geod_ini();
	/* check if line or arc mode */
	if (pj_param(NULL,start, "tlat_1").i) {
		double del_S;
#undef f
		phi1 = pj_param(NULL,start, "rlat_1").f;
		lam1 = pj_param(NULL,start, "rlon_1").f;
		if (pj_param(NULL,start, "tlat_2").i) {
			phi2 = pj_param(NULL,start, "rlat_2").f;
			lam2 = pj_param(NULL,start, "rlon_2").f;
			geod_inv();
			geod_pre();
		} else if ((geod_S = pj_param(NULL,start, "dS").f) != 0.) {
			al12 = pj_param(NULL,start, "rA").f;
			geod_pre();
			geod_for();
		} else emess(1,"incomplete geodesic/arc info");
		if ((n_alpha = pj_param(NULL,start, "in_A").i) > 0) {
			if (!(del_alpha = pj_param(NULL,start, "rdel_A").f))
				emess(1,"del azimuth == 0");
		} else if ((del_S = fabs(pj_param(NULL,start, "ddel_S").f)) != 0.) {
			n_S = (int)(geod_S / del_S + .5);
		} else if ((n_S = pj_param(NULL,start, "in_S").i) <= 0)
			emess(1,"no interval divisor selected");
	}
	/* free up linked list */
	for ( ; start; start = curr) {
		curr = start->next;
		pj_dalloc(start);
	}
}
コード例 #4
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
int proj_context_errno (PJ_CONTEXT *ctx) {
/******************************************************************************
    Read an error directly from a context, without going through a PJ
    belonging to that context.
******************************************************************************/
    if (0==ctx)
        ctx = pj_get_default_ctx();
    return pj_ctx_get_errno (ctx);
}
コード例 #5
0
ファイル: pj_ctx.c プロジェクト: hurenkam/proj.4
projCtx pj_ctx_alloc()

{
    projCtx ctx = (projCtx_t *) malloc(sizeof(projCtx_t));
    memcpy( ctx, pj_get_default_ctx(), sizeof(projCtx_t) );
    ctx->last_errno = 0;

    return ctx;
}
コード例 #6
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) {
    if (0==ctx)
        return 0;

    /* Trying to free the default context is a no-op (since it is statically allocated) */
    if (pj_get_default_ctx ()==ctx)
        return 0;

    pj_ctx_free (ctx);
    return 0;
}
コード例 #7
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
PJ_GRID_INFO proj_grid_info(const char *gridname) {
/******************************************************************************
    Information about a named datum grid.

    Returns PJ_GRID_INFO struct.
******************************************************************************/
    PJ_GRID_INFO grinfo;

    /*PJ_CONTEXT *ctx = proj_context_create(); */
    PJ_CONTEXT *ctx = pj_get_default_ctx();
    PJ_GRIDINFO *gridinfo = pj_gridinfo_init(ctx, gridname);
    memset(&grinfo, 0, sizeof(PJ_GRID_INFO));

    /* in case the grid wasn't found */
    if (gridinfo->filename == NULL) {
        pj_gridinfo_free(ctx, gridinfo);
        strcpy(grinfo.format, "missing");
        return grinfo;
    }

    /* The string copies below are automatically null-terminated due to */
    /* the memset above, so strncpy is safe */

    /* name of grid */
    strncpy (grinfo.gridname, gridname, sizeof(grinfo.gridname) - 1);

    /* full path of grid */
    pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1);

    /* grid format */
    strncpy (grinfo.format, gridinfo->format, sizeof(grinfo.format) - 1);

    /* grid size */
    grinfo.n_lon = gridinfo->ct->lim.lam;
    grinfo.n_lat = gridinfo->ct->lim.phi;

    /* cell size */
    grinfo.cs_lon = gridinfo->ct->del.lam;
    grinfo.cs_lat = gridinfo->ct->del.phi;

    /* bounds of grid */
    grinfo.lowerleft  = gridinfo->ct->ll;
    grinfo.upperright.lam = grinfo.lowerleft.lam + grinfo.n_lon*grinfo.cs_lon;
    grinfo.upperright.phi = grinfo.lowerleft.phi + grinfo.n_lat*grinfo.cs_lat;

    pj_gridinfo_free(ctx, gridinfo);

    return grinfo;
}
コード例 #8
0
ファイル: proj_4D_api.c プロジェクト: ampimis/RtkGps
PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) {
/**************************************************************************************
    Create a new PJ object in the context ctx, using the given definition. If ctx==0,
    the default context is used, if definition==0, or invalid, a null-pointer is
    returned. The definition may use '+' as argument start indicator, as in
    "+proj=utm +zone=32", or leave it out, as in "proj=utm zone=32".

    It may even use free formatting "proj  =  utm;  zone  =32  ellps= GRS80".
    Note that the semicolon separator is allowed, but not required.
**************************************************************************************/
    PJ    *P;
    char  *args, **argv;
    size_t argc, n;
    int    ret;

    if (0==ctx)
        ctx = pj_get_default_ctx ();

    /* Make a copy that we can manipulate */
    n = strlen (definition);
    args = (char *) malloc (n + 1);
    if (0==args)
        return 0;
    strcpy (args, definition);

    argc = pj_trim_argc (args);
    if (argc==0) {
        pj_dealloc (args);
        return 0;
    }

    argv = pj_trim_argv (argc, args);

    /* ...and let pj_init_ctx do the hard work */
    P = pj_init_ctx (ctx, (int) argc, argv);

    pj_dealloc (argv);
    pj_dealloc (args);

    /* Support cs2cs-style modifiers */
    ret = cs2cs_emulation_setup  (P);
    if (0==ret)
        return proj_destroy (P);

    return P;
}
コード例 #9
0
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
{
    if( len > 1000 )
    {
#ifdef STANDALONE
        fprintf(stderr, "Input too large\n");
#endif
        return 0;
    }

    /* We expect the blob to be 2 lines: */
    /* source_string\ndestination_string */
    char* buf_dup = (char*)malloc(len+1);
    memcpy(buf_dup, buf, len);
    buf_dup[len] = 0;
    char* first_line = buf_dup;
    char* first_newline = strchr(first_line, '\n');
    if( !first_newline )
    {
        free(buf_dup);
        return 0;
    }
    first_newline[0] = 0;
    char* second_line = first_newline + 1;

#ifdef STANDALONE
    fprintf(stderr, "src=%s\n", first_line);
    fprintf(stderr, "dst=%s\n", second_line);
#endif

    proj_destroy(
        proj_create_crs_to_crs(nullptr, first_line, second_line, nullptr));

    free(buf_dup);
    pj_gc_unloadall(pj_get_default_ctx());
    pj_deallocate_grids();
    return 0;
}
コード例 #10
0
ファイル: dmstor.cpp プロジェクト: Navionics/proj.4
	double
dmstor(const char *is, char **rs) {
	return dmstor_ctx( pj_get_default_ctx(), is, rs );
}
コード例 #11
0
ファイル: multistresstest.c プロジェクト: ampimis/RtkGps
static int do_main(void)
#endif
{
/* -------------------------------------------------------------------- */
/*      Our first pass is to establish the correct answers for all      */
/*      the tests.                                                      */
/* -------------------------------------------------------------------- */
    int i, test_count = sizeof(test_list) / sizeof(TestItem);

    for( i = 0; i < test_count; i++ )
    {
        TestItem *test = test_list + i;

        projPJ src_pj, dst_pj;

        src_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->src_def );
        dst_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->dst_def );

        if( src_pj == NULL )
        {
            printf( "Unable to translate:\n%s\n", test->src_def );
            test->skip = 1;
            pj_free (dst_pj);
            continue;
        }

        if( dst_pj == NULL )
        {
            printf( "Unable to translate:\n%s\n", test->dst_def );
            test->skip = 1;
            pj_free (src_pj);
            continue;
        }

        test->dst_x = test->src_x;
        test->dst_y = test->src_y;
        test->dst_z = test->src_z;

        test->dst_error = pj_transform( src_pj, dst_pj, 1, 0,
                                        &(test->dst_x),
                                        &(test->dst_y),
                                        &(test->dst_z) );

        pj_free( src_pj );
        pj_free( dst_pj );

        test->skip = 0;

#ifdef notdef
        printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst_x, test->dst_y, test->dst_z );
#endif
    }

    printf( "%d tests initialized.\n", test_count );

/* -------------------------------------------------------------------- */
/*      Now launch a bunch of threads to repeat the tests.              */
/* -------------------------------------------------------------------- */
#ifdef _WIN32

    { //Scoped to workaround lack of c99 support in VS
        HANDLE ahThread[num_threads];

        for( i = 0; i < num_threads; i++ )
        {
            active_thread_count++;

            ahThread[i] = CreateThread(NULL, 0, WinTestThread, NULL, 0, NULL);

            if (ahThread[i] == 0)
            {
                printf( "Thread creation failed.");
                return 1;
            }
        }

        printf( "%d test threads launched.\n", num_threads );

        WaitForMultipleObjects(num_threads, ahThread, TRUE, INFINITE);
    }

#else
    {
    pthread_t ahThread[num_threads];
    pthread_attr_t hThreadAttr;

    pthread_attr_init( &hThreadAttr );
    pthread_attr_setdetachstate( &hThreadAttr, PTHREAD_CREATE_DETACHED );

    for( i = 0; i < num_threads; i++ )
    {
        active_thread_count++;

        pthread_create( &(ahThread[i]), &hThreadAttr,
            PosixTestThread, NULL );
    }

    printf( "%d test threads launched.\n", num_threads );

    while( active_thread_count > 0 )
        sleep( 1 );
    }
#endif

    printf( "all tests complete.\n" );

    return 0;
}
コード例 #12
0
ファイル: pj_init.c プロジェクト: ampimis/RtkGps
PJ *
pj_init_ctx(projCtx ctx, int argc, char **argv) {
    char *s, *name;
    PJ_CONSTRUCTOR proj;
    paralist *curr, *init, *start;
    int i;
    int err;
    PJ *PIN = 0;
    int n_pipelines = 0;
    int n_inits = 0;

    if (0==ctx)
        ctx = pj_get_default_ctx ();

    ctx->last_errno = 0;

    if (argc <= 0) {
        pj_ctx_set_errno (ctx, PJD_ERR_NO_ARGS);
        return 0;
    }

    /* count occurrences of pipelines and inits */
    for (i = 0; i < argc; ++i) {
        if (!strcmp (argv[i], "+proj=pipeline") || !strcmp(argv[i], "proj=pipeline") )
                n_pipelines++;
        if (!strncmp (argv[i], "+init=", 6) || !strncmp(argv[i], "init=", 5))
            n_inits++;
    }

    /* can't have nested pipelines directly */
    if (n_pipelines > 1) {
        pj_ctx_set_errno (ctx, PJD_ERR_MALFORMED_PIPELINE);
        return 0;
    }

    /* don't allow more than one +init in non-pipeline operations */
    if (n_pipelines == 0 && n_inits > 1) {
        pj_ctx_set_errno (ctx, PJD_ERR_TOO_MANY_INITS);
        return 0;
    }


    /* put arguments into internal linked list */
    start = curr = pj_mkparam(argv[0]);
    if (!curr)
        return pj_dealloc_params (ctx, start, ENOMEM);

    for (i = 1; i < argc; ++i) {
        curr->next = pj_mkparam(argv[i]);
        if (!curr->next)
            return pj_dealloc_params (ctx, start, ENOMEM);
        curr = curr->next;
    }


    /* Only expand '+init's in non-pipeline operations. '+init's in pipelines are */
    /* expanded in the individual pipeline steps during pipeline initialization.  */
    /* Potentially this leads to many nested pipelines, which shouldn't be a      */
    /* problem when '+init's are expanded as late as possible.                    */
    init = pj_param_exists (start, "init");
    if (init && n_pipelines == 0) {
        init = pj_expand_init (ctx, init);
        if (!init)
            return pj_dealloc_params (ctx, start, PJD_ERR_NO_ARGS);
    }
    if (ctx->last_errno)
        return pj_dealloc_params (ctx, start, ctx->last_errno);

    /* Find projection selection */
    curr = pj_param_exists (start, "proj");
    if (0==curr)
        return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
    name =  curr->param;
    if (strlen (name) < 6)
        return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
    name += 5;

    proj = locate_constructor (name);
    if (0==proj)
        return pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);


    /* Append general and projection specific defaults to the definition list */
    append_defaults_to_paralist (ctx, start, "general");
    append_defaults_to_paralist (ctx, start, name);


    /* Allocate projection structure */
    PIN = proj(0);
    if (0==PIN)
        return pj_dealloc_params (ctx, start, ENOMEM);


    PIN->ctx = ctx;
    PIN->params = start;
    PIN->is_latlong = 0;
    PIN->is_geocent = 0;
    PIN->is_long_wrap_set = 0;
    PIN->long_wrap_center = 0.0;
    strcpy( PIN->axis, "enu" );

    PIN->gridlist = NULL;
    PIN->gridlist_count = 0;

    PIN->vgridlist_geoid = NULL;
    PIN->vgridlist_geoid_count = 0;

    /* Set datum parameters. Similarly to +init parameters we want to expand    */
    /* +datum parameters as late as possible when dealing with pipelines.       */
    /* otherwise only the first occurrence of +datum will be expanded and that */
    if (n_pipelines == 0) {
        if (pj_datum_set(ctx, start, PIN))
            return pj_default_destructor (PIN, proj_errno(PIN));
    }

    err = pj_ellipsoid (PIN);

    if (err) {
        /* Didn't get an ellps, but doesn't need one: Get a free WGS84 */
        if (PIN->need_ellps) {
            pj_log (ctx, PJ_LOG_DEBUG_MINOR, "pj_init_ctx: Must specify ellipsoid or sphere");
            return pj_default_destructor (PIN, proj_errno(PIN));
        }
        else {
            if (PJD_ERR_MAJOR_AXIS_NOT_GIVEN==proj_errno (PIN))
                proj_errno_reset (PIN);
            PIN->f = 1.0/298.257223563;
            PIN->a_orig  = PIN->a  = 6378137.0;
            PIN->es_orig = PIN->es = PIN->f*(2-PIN->f);
        }
    }
    PIN->a_orig = PIN->a;
    PIN->es_orig = PIN->es;
    if (pj_calc_ellipsoid_params (PIN, PIN->a, PIN->es))
        return pj_default_destructor (PIN, PJD_ERR_ECCENTRICITY_IS_ONE);

    /* Now that we have ellipse information check for WGS84 datum */
    if( PIN->datum_type == PJD_3PARAM
        && PIN->datum_params[0] == 0.0
        && PIN->datum_params[1] == 0.0
        && PIN->datum_params[2] == 0.0
        && PIN->a == 6378137.0
        && ABS(PIN->es - 0.006694379990) < 0.000000000050 )/*WGS84/GRS80*/
    {
        PIN->datum_type = PJD_WGS84;
    }

    /* Set PIN->geoc coordinate system */
    PIN->geoc = (PIN->es != 0.0 && pj_param(ctx, start, "bgeoc").i);

    /* Over-ranging flag */
    PIN->over = pj_param(ctx, start, "bover").i;

    /* Vertical datum geoid grids */
    PIN->has_geoid_vgrids = pj_param(ctx, start, "tgeoidgrids").i;
    if( PIN->has_geoid_vgrids ) /* we need to mark it as used. */
        pj_param(ctx, start, "sgeoidgrids");

    /* Longitude center for wrapping */
    PIN->is_long_wrap_set = pj_param(ctx, start, "tlon_wrap").i;
    if (PIN->is_long_wrap_set) {
        PIN->long_wrap_center = pj_param(ctx, start, "rlon_wrap").f;
        /* Don't accept excessive values otherwise we might perform badly */
        /* when correcting longitudes around it */
        /* The test is written this way to error on long_wrap_center "=" NaN */
        if( !(fabs(PIN->long_wrap_center) < 10 * M_TWOPI) )
            return pj_default_destructor (PIN, PJD_ERR_LAT_OR_LON_EXCEED_LIMIT);
    }

    /* Axis orientation */
    if( (pj_param(ctx, start,"saxis").s) != NULL )
    {
        const char *axis_legal = "ewnsud";
        const char *axis_arg = pj_param(ctx, start,"saxis").s;
        if( strlen(axis_arg) != 3 )
            return pj_default_destructor (PIN, PJD_ERR_AXIS);

        if( strchr( axis_legal, axis_arg[0] ) == NULL
            || strchr( axis_legal, axis_arg[1] ) == NULL
            || strchr( axis_legal, axis_arg[2] ) == NULL)
            return pj_default_destructor (PIN, PJD_ERR_AXIS);

        /* TODO: it would be nice to validate we don't have on axis repeated */
        strcpy( PIN->axis, axis_arg );
    }

    /* Central meridian */
    PIN->lam0=pj_param(ctx, start, "rlon_0").f;

    /* Central latitude */
    PIN->phi0 = pj_param(ctx, start, "rlat_0").f;

    /* False easting and northing */
    PIN->x0 = pj_param(ctx, start, "dx_0").f;
    PIN->y0 = pj_param(ctx, start, "dy_0").f;
    PIN->z0 = pj_param(ctx, start, "dz_0").f;
    PIN->t0 = pj_param(ctx, start, "dt_0").f;

    /* General scaling factor */
    if (pj_param(ctx, start, "tk_0").i)
        PIN->k0 = pj_param(ctx, start, "dk_0").f;
    else if (pj_param(ctx, start, "tk").i)
        PIN->k0 = pj_param(ctx, start, "dk").f;
    else
        PIN->k0 = 1.;
    if (PIN->k0 <= 0.)
        return pj_default_destructor (PIN, PJD_ERR_K_LESS_THAN_ZERO);

    /* Set units */
    s = 0;
    if ((name = pj_param(ctx, start, "sunits").s) != NULL) {
        for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ;
        if (!s)
            return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
        s = pj_units[i].to_meter;
    }
    if (s || (s = pj_param(ctx, start, "sto_meter").s)) {
        double factor;
        int ratio = 0;

        /* ratio number? */
        if (strlen (s) > 1 && s[0] == '1' && s[1]=='/') {
            ratio = 1;
            s += 2;
        }

        factor = pj_strtod(s, &s);
        if ((factor <= 0.0) || (1/factor==0))
            return pj_default_destructor (PIN, PJD_ERR_UNIT_FACTOR_LESS_THAN_0);

        PIN->to_meter = ratio?  1 / factor: factor;
        PIN->fr_meter = 1 / PIN->to_meter;

    } else
        PIN->to_meter = PIN->fr_meter = 1.;

    /* Set vertical units */
    s = 0;
    if ((name = pj_param(ctx, start, "svunits").s) != NULL) {
        for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ;
        if (!s)
            return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
        s = pj_units[i].to_meter;
    }
    if (s || (s = pj_param(ctx, start, "svto_meter").s)) {
        PIN->vto_meter = pj_strtod(s, &s);
        if (*s == '/') /* ratio number */
            PIN->vto_meter /= pj_strtod(++s, 0);
        if (PIN->vto_meter <= 0.0)
            return pj_default_destructor (PIN, PJD_ERR_UNIT_FACTOR_LESS_THAN_0);
        PIN->vfr_meter = 1. / PIN->vto_meter;
    } else {
        PIN->vto_meter = PIN->to_meter;
        PIN->vfr_meter = PIN->fr_meter;
    }

    /* Prime meridian */
    s = 0;
    if ((name = pj_param(ctx, start, "spm").s) != NULL) {
        const char *value = NULL;
        char *next_str = NULL;

        for (i = 0; pj_prime_meridians[i].id != NULL; ++i )
        {
            if( strcmp(name,pj_prime_meridians[i].id) == 0 )
            {
                value = pj_prime_meridians[i].defn;
                break;
            }
        }

        if( value == NULL
            && (dmstor_ctx(ctx,name,&next_str) != 0.0  || *name == '0')
            && *next_str == '\0' )
            value = name;

        if (!value)
            return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_PRIME_MERIDIAN);
        PIN->from_greenwich = dmstor_ctx(ctx,value,NULL);
    }
    else
        PIN->from_greenwich = 0.0;

    /* Private object for the geodesic functions */
    PIN->geod = pj_calloc (1, sizeof (struct geod_geodesic));
    if (0==PIN->geod)
        return pj_default_destructor (PIN, ENOMEM);
    geod_init(PIN->geod, PIN->a,  (1 - sqrt (1 - PIN->es)));

    /* Projection specific initialization */
    err = proj_errno_reset (PIN);
    PIN = proj(PIN);
    if (proj_errno (PIN)) {
        pj_free(PIN);
        return 0;
    }
    proj_errno_restore (PIN, err);
    return PIN;
}
コード例 #13
0
ファイル: pj_init.c プロジェクト: ampimis/RtkGps
PJ *
pj_init(int argc, char **argv) {
    return pj_init_ctx( pj_get_default_ctx(), argc, argv );
}
コード例 #14
0
ファイル: pj_init.c プロジェクト: ampimis/RtkGps
PJ *
pj_init_plus( const char *definition )

{
    return pj_init_plus_ctx( pj_get_default_ctx(), definition );
}
コード例 #15
0
ファイル: cs2cs.c プロジェクト: joa-quim/MB-system-Win
int main(int argc, char **argv) {
	char *arg, **eargv = argv, *from_argv[MAX_PARGS], *to_argv[MAX_PARGS], **iargv = argv;
	FILE *fid;
	int from_argc = 0, to_argc = 0, iargc = argc, eargc = 0, c, mon = 0;
	int have_to_flag = 0, inverse = 0, i;

	if ((emess_dat.Prog_name = strrchr(*argv, DIR_CHAR)) != NULL)
		++emess_dat.Prog_name;
	else
		emess_dat.Prog_name = *argv;
	inverse = !strncmp(emess_dat.Prog_name, "inv", 3);
	if (argc <= 1) {
		(void)fprintf(stderr, usage, pj_get_release(), emess_dat.Prog_name);
		exit(0);
	}
	/* process run line arguments */
	while (--argc > 0) { /* collect run line arguments */
		if (**++argv == '-')
			for (arg = *argv;;) {
				switch (*++arg) {
				case '\0': /* position of "stdin" */
					if (arg[-1] == '-')
						eargv[eargc++] = "-";
					break;
				case 'v': /* monitor dump of initialization */
					mon = 1;
					continue;
				case 'I': /* alt. method to spec inverse */
					inverse = 1;
					continue;
				case 'E': /* echo ascii input to ascii output */
					echoin = 1;
					continue;
				case 't': /* set col. one char */
					if (arg[1])
						tag = *++arg;
					else
						emess(1, "missing -t col. 1 tag");
					continue;
				case 'l': /* list projections, ellipses or units */
					if (!arg[1] || arg[1] == 'p' || arg[1] == 'P') {
						/* list projections */
						struct PJ_LIST *lp;
						int do_long = arg[1] == 'P', c;
						char *str;

						for (lp = pj_get_list_ref(); lp->id; ++lp) {
							(void)printf("%s : ", lp->id);
							if (do_long) /* possibly multiline description */
								(void)puts(*lp->descr);
							else { /* first line, only */
								str = *lp->descr;
								while ((c = *str++) && c != '\n')
									putchar(c);
								putchar('\n');
							}
						}
					}
					else if (arg[1] == '=') { /* list projection 'descr' */
						struct PJ_LIST *lp;

						arg += 2;
						for (lp = pj_get_list_ref(); lp->id; ++lp)
							if (!strcmp(lp->id, arg)) {
								(void)printf("%9s : %s\n", lp->id, *lp->descr);
								break;
							}
					}
					else if (arg[1] == 'e') { /* list ellipses */
						struct PJ_ELLPS *le;

						for (le = pj_get_ellps_ref(); le->id; ++le)
							(void)printf("%9s %-16s %-16s %s\n", le->id, le->major, le->ell, le->name);
					}
					else if (arg[1] == 'u') { /* list units */
						struct PJ_UNITS *lu;

						for (lu = pj_get_units_ref(); lu->id; ++lu)
							(void)printf("%12s %-20s %s\n", lu->id, lu->to_meter, lu->name);
					}
					else if (arg[1] == 'd') { /* list datums */
						struct PJ_DATUMS *ld;

						printf("__datum_id__ __ellipse___ __definition/comments______________________________\n");
						for (ld = pj_get_datums_ref(); ld->id; ++ld) {
							printf("%12s %-12s %-30s\n", ld->id, ld->ellipse_id, ld->defn);
							if (ld->comments != NULL && strlen(ld->comments) > 0)
								printf("%25s %s\n", " ", ld->comments);
						}
					}
					else if (arg[1] == 'm') { /* list prime meridians */
						struct PJ_PRIME_MERIDIANS *lpm;

						for (lpm = pj_get_prime_meridians_ref(); lpm->id; ++lpm)
							(void)printf("%12s %-30s\n", lpm->id, lpm->defn);
					}
					else
						emess(1, "invalid list option: l%c", arg[1]);
					exit(0);
					continue; /* artificial */
				case 'e':     /* error line alternative */
					if (--argc <= 0)
					noargument:
						emess(1, "missing argument for -%c", *arg);
					oterr = *++argv;
					continue;
				case 'W': /* specify seconds precision */
				case 'w': /* -W for constant field width */
					if ((c = arg[1]) != 0 && isdigit(c)) {
						set_rtodms(c - '0', *arg == 'W');
						++arg;
					}
					else
						emess(1, "-W argument missing or non-digit");
					continue;
				case 'f': /* alternate output format degrees or xy */
					if (--argc <= 0)
						goto noargument;
					oform = *++argv;
					continue;
				case 'r': /* reverse input */
					reversein = 1;
					continue;
				case 's': /* reverse output */
					reverseout = 1;
					continue;
				case 'd': /* set debug level */
					if (--argc <= 0)
						goto noargument;
					pj_ctx_set_debug(pj_get_default_ctx(), atoi(*++argv));
					continue;
				default:
					emess(1, "invalid option: -%c", *arg);
					break;
				}
				break;
			}
		else if (strcmp(*argv, "+to") == 0) {
			have_to_flag = 1;
		}
		else if (**argv == '+') { /* + argument */
			if (have_to_flag) {
				if (to_argc < MAX_PARGS)
					to_argv[to_argc++] = *argv + 1;
				else
					emess(1, "overflowed + argument table");
			}
			else {
				if (from_argc < MAX_PARGS)
					from_argv[from_argc++] = *argv + 1;
				else
					emess(1, "overflowed + argument table");
			}
		}
		else /* assumed to be input file name(s) */
			eargv[eargc++] = *argv;
	}
	if (eargc == 0) /* if no specific files force sysin */
		eargv[eargc++] = "-";

	/*
	 * If the user has requested inverse, then just reverse the
	 * coordinate systems.
	 */
	if (inverse) {
		int argcount;

		for (i = 0; i < MAX_PARGS; i++) {
			char *arg;

			arg = from_argv[i];
			from_argv[i] = to_argv[i];
			to_argv[i] = arg;
		}

		argcount = from_argc;
		from_argc = to_argc;
		to_argc = argcount;
	}

	if (!(fromProj = pj_init(from_argc, from_argv))) {
		printf("Using from definition: ");
		for (i = 0; i < from_argc; i++)
			printf("%s ", from_argv[i]);
		printf("\n");

		emess(3, "projection initialization failure\ncause: %s", pj_strerrno(pj_errno));
	}

	if (to_argc == 0) {
		if (!(toProj = pj_latlong_from_proj(fromProj))) {
			printf("Using to definition: ");
			for (i = 0; i < to_argc; i++)
				printf("%s ", to_argv[i]);
			printf("\n");

			emess(3, "projection initialization failure\ncause: %s", pj_strerrno(pj_errno));
		}
	}
	else if (!(toProj = pj_init(to_argc, to_argv))) {
		printf("Using to definition: ");
		for (i = 0; i < to_argc; i++)
			printf("%s ", to_argv[i]);
		printf("\n");

		emess(3, "projection initialization failure\ncause: %s", pj_strerrno(pj_errno));
	}

	if (mon) {
		printf("%c ---- From Coordinate System ----\n", tag);
		pj_pr_list(fromProj);
		printf("%c ---- To Coordinate System ----\n", tag);
		pj_pr_list(toProj);
	}

	/* set input formating control */
	if (!fromProj->is_latlong)
		informat = strtod;
	else {
		informat = dmstor;
	}

	if (!toProj->is_latlong && !oform)
		oform = "%.2f";

	/* process input file list */
	for (; eargc--; ++eargv) {
		if (**eargv == '-') {
			fid = stdin;
			emess_dat.File_name = "<stdin>";
		}
		else {
			if ((fid = fopen(*eargv, "rt")) == NULL) {
				emess(-2, *eargv, "input file");
				continue;
			}
			emess_dat.File_name = *eargv;
		}
		emess_dat.File_line = 0;
		process(fid);
		fclose(fid);
		emess_dat.File_name = 0;
	}

	if (fromProj != NULL)
		pj_free(fromProj);
	if (toProj != NULL)
		pj_free(toProj);

	pj_deallocate_grids();

	exit(0); /* normal completion */
}
コード例 #16
0
ファイル: standard_fuzzer.cpp プロジェクト: Navionics/proj.4
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
{
    if( len > 1000 )
    {
#ifdef STANDALONE
        fprintf(stderr, "Input too large\n");
#endif
        return 0;
    }

    /* We expect the blob to be 3 lines: */
    /* source proj string\ndestination proj string\nx y */
    char* buf_dup = (char*)malloc(len+1);
    memcpy(buf_dup, buf, len);
    buf_dup[len] = 0;
    char* first_line = buf_dup;
    char* first_newline = strchr(first_line, '\n');
    if( !first_newline )
    {
        free(buf_dup);
        return 0;
    }
    first_newline[0] = 0;
    char* second_line = first_newline + 1;
    char* second_newline = strchr(second_line, '\n');
    if( !second_newline )
    {
        free(buf_dup);
        return 0;
    }
    second_newline[0] = 0;
    char* third_line = second_newline + 1;
    projPJ pj_src = pj_init_plus(first_line);
    if( !pj_src )
    {
        free(buf_dup);
        return 0;
    }
    projPJ pj_dst = pj_init_plus(second_line);
    if( !pj_dst )
    {
        free(buf_dup);
        pj_free(pj_src);
        pj_gc_unloadall(pj_get_default_ctx());
        pj_deallocate_grids();
        return 0;
    }
    double x = 0, y = 0, z = 9;
    bool from_binary = false;
    bool has_z = false;
    if( strncmp(third_line, "BINARY_2D:", strlen("BINARY_2D:")) == 0 &&
        third_line - first_line + strlen("BINARY_2D:") + 2 * sizeof(double) <= len )
    {
        from_binary = true;
        memcpy(&x, third_line + strlen("BINARY_2D:"), sizeof(double));
        memcpy(&y, third_line + strlen("BINARY_2D:") + sizeof(double), sizeof(double));
    }
    else if( strncmp(third_line, "BINARY_3D:", strlen("BINARY_3D:")) == 0 &&
             third_line - first_line + strlen("BINARY_3D:") + 3 * sizeof(double) <= len )
    {
        from_binary = true;
        has_z = true;
        memcpy(&x, third_line + strlen("BINARY_3D:"), sizeof(double));
        memcpy(&y, third_line + strlen("BINARY_3D:") + sizeof(double), sizeof(double));
        memcpy(&z, third_line + strlen("BINARY_3D:") + 2 * sizeof(double), sizeof(double));
    }
    else if( sscanf(third_line, "%lf %lf", &x, &y) != 2 )
    {
        free(buf_dup);
        pj_free(pj_src);
        pj_free(pj_dst);
        pj_gc_unloadall(pj_get_default_ctx());
        pj_deallocate_grids();
        return 0;
    }
#ifdef STANDALONE
    fprintf(stderr, "src=%s\n", first_line);
    fprintf(stderr, "dst=%s\n", second_line);
    if( from_binary )
    {
        if( has_z )
            fprintf(stderr, "coord (from binary)=%.18g %.18g %.18g\n", x, y, z);
        else
            fprintf(stderr, "coord (from binary)=%.18g %.18g\n", x, y);
    }
    else
        fprintf(stderr, "coord=%s\n", third_line);
#endif
    if( has_z )
        pj_transform( pj_src, pj_dst, 1, 0, &x, &y, &z );
    else
        pj_transform( pj_src, pj_dst, 1, 0, &x, &y, NULL );
    free(buf_dup);
    pj_free(pj_src);
    pj_free(pj_dst);
    pj_gc_unloadall(pj_get_default_ctx());
    pj_deallocate_grids();
    return 0;
}