コード例 #1
0
ファイル: gvrecttool.c プロジェクト: midendian/openev2
static void 
gv_rect_tool_reshape( GvRectTool *r_tool, gvgeocoord x, gvgeocoord y )

{
    GvShape *shape;
    gvgeocoord   x1, y1, x2, y2;

    gv_tool_clamp_to_bounds( GV_TOOL(r_tool), &x, &y );

    shape = gv_shapes_get_shape( r_tool->layer->data, r_tool->shape_id );
    if( shape == NULL || gv_shape_get_nodes( shape, 0 ) != 5 )
        return;

    shape = gv_shape_copy( shape );

    x1 = gv_shape_get_x(shape,0,0);
    y1 = gv_shape_get_y(shape,0,0);
    x2 = gv_shape_get_x(shape,0,2);
    y2 = gv_shape_get_y(shape,0,2);

    if( r_tool->picked == PICK_SIDE_TOP )
        y1 = y;
    else if( r_tool->picked == PICK_SIDE_RIGHT )
        x2 = x;
    else if( r_tool->picked == PICK_SIDE_BOTTOM )
        y2 = y;
    else if( r_tool->picked == PICK_SIDE_LEFT )
        x1 = x;
    else if( r_tool->picked == PICK_CORNER_TOPLEFT )
    {
        x1 = x;
        y1 = y;
    }
    else if( r_tool->picked == PICK_CORNER_TOPRIGHT )
    {
        x2 = x;
        y1 = y;
    }
    else if( r_tool->picked == PICK_CORNER_BOTTOMRIGHT )
    {
        x2 = x;
        y2 = y;
    }
    else if( r_tool->picked == PICK_CORNER_BOTTOMLEFT )
    {
        x1 = x;
        y2 = y;
    }

    gv_shape_set_xyz( shape, 0, 0, x1, y1, 0 );
    gv_shape_set_xyz( shape, 0, 1, x1, y2, 0 );
    gv_shape_set_xyz( shape, 0, 2, x2, y2, 0 );
    gv_shape_set_xyz( shape, 0, 3, x2, y1, 0 );
    gv_shape_set_xyz( shape, 0, 4, x1, y1, 0 );

    gv_shapes_replace_shapes( r_tool->layer->data, 1, &(r_tool->shape_id),
                              &shape, FALSE );
}
コード例 #2
0
ファイル: gvpointtool.c プロジェクト: Onjrew/OpenEV
static void
gv_point_tool_button_press(GvTool *tool, GdkEventButton *event)
{
    if (event->button == 1)
    {
	GvVertex vertex;
	
	if (!gv_point_tool_configure(tool)) return;

	/* Get pointer location */
	gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
				 &vertex.x, &vertex.y);

        if( !gv_tool_check_bounds( GV_TOOL(tool), vertex.x, vertex.y ) )
            return;

	/* Add a new point */
        if( GV_IS_POINT_LAYER(GV_POINT_TOOL(tool)->layer) )
        {
            gv_point_layer_select_new_point(
                GV_POINT_LAYER(GV_POINT_TOOL(tool)->layer), 
                &vertex);
        }
        else
        {
            GvShape   *new_point;

            new_point = gv_shape_new( GVSHAPE_POINT );
            gv_shape_set_xyz( new_point, 0, 0, vertex.x, vertex.y, 0.0 );
            gv_shapes_layer_select_new_shape( 
                GV_SHAPES_LAYER(GV_POINT_TOOL(tool)->layer), 
                new_point );
        }
    }
}
コード例 #3
0
ファイル: gvshapes.c プロジェクト: midendian/openev2
void
gv_shapes_translate_shapes(GvShapes *shapes, gint num_shapes, gint *id_list,
                           gvgeocoord dx, gvgeocoord dy)
{
    GvShape *shape;
    gint i;
    GvShapeChangeInfo change_info = {GV_CHANGE_REPLACE, 0, NULL};

    change_info.num_shapes = num_shapes;
    change_info.shape_id = id_list;

    gv_data_changing(GV_DATA(shapes), &change_info);

    for (i=0; i < num_shapes; ++i)
    {
        int    ring;

        shape = gv_shapes_get_shape(shapes,id_list[i]);
        if( shape == NULL )
            continue;

        for( ring = gv_shape_get_rings(shape)-1; ring >= 0; ring-- )
        {
            int    node;

            for( node = gv_shape_get_nodes(shape,ring)-1;
                 node >= 0; node-- )
            {
                gv_shape_set_xyz( shape, ring, node,
                                  gv_shape_get_x(shape, ring, node) + dx,
                                  gv_shape_get_y(shape, ring, node) + dy,
                                  gv_shape_get_z(shape, ring, node) );
            }
        }
    }
    gv_data_changed(GV_DATA(shapes), &change_info);
}
コード例 #4
0
ファイル: gvshapes.c プロジェクト: midendian/openev2
void
gv_shapes_add_height(GvShapes *shapes, GvData *raster_data, double offset,
                     double default_height)
{
    int success, i, num_shapes;
    double x, y, z, last_z, imaginary, nodata_value;
    GvRaster *raster = GV_RASTER(raster_data);
    GvShapeChangeInfo change_info = {GV_CHANGE_REPLACE, 0, NULL};
    int    *id_list;

    /*
     * Notify of impending change.
     */
    num_shapes = gv_shapes_num_shapes(shapes);
    id_list = g_new( int, num_shapes );

    change_info.num_shapes = 0;
    change_info.shape_id = id_list;

    for (i=0; i < num_shapes; i++)
    {
        if( gv_shapes_get_shape(shapes,i) != NULL )
            id_list[change_info.num_shapes++] = i;
    }

    gv_data_changing(GV_DATA(shapes), &change_info);

    /*
     * Establish the "nodata" value.
     */
    success = gv_raster_get_nodata( raster, &nodata_value );
    if( !success )
        nodata_value = -1e8;

    /*
     * Loop over all shapes, applying height.
     */
    for (i=0; i < num_shapes; i++)
    {
        GvShape *shape = gv_shapes_get_shape(shapes,i);
        int     ring, ring_count = gv_shape_get_rings( shape );

        if( shape == NULL )
            continue;

        last_z = default_height;

        for( ring = 0; ring < ring_count; ring++ )
        {
            int node, node_count = gv_shape_get_nodes( shape, ring );

            for( node = 0; node < node_count; node++ )
            {
                double  x_orig, y_orig;

                /* get xy in image space */
                x_orig = x = gv_shape_get_x( shape, ring, node );
                y_orig = y = gv_shape_get_y( shape, ring, node );
                z = 0.0;

                if (!gv_raster_georef_to_pixel(raster, &x, &y, &z))
                {
                    fprintf(stderr, "ERROR raster_georef_to_pixel failed!!!\n");
                    break;
                }

                if( x > -1.0 && x < 0.0 )
                    x = 0.0;
                if( y > -1.0 && y < 0.0 )
                    y = 0.0;
                if( x >= raster->width && x < raster->width+1 )
                    x = raster->width - 0.01;
                if( y >= raster->height && y < raster->height+1 )
                    y = raster->height - 0.01;

                /* Check if mesh xy values outside of height raster
                   - leave as 0 */
                if( x >= 0.0 && x < raster->width
                    && y >= 0.0 && y < raster->height )
                {
                    if (!gv_raster_get_sample(raster, x, y, &z, &imaginary))
                    {
                        fprintf(stderr,
                                "ERROR raster_get_sample failed for (x y z) %f %f\n",
                                x, y);
                    }
                    else
                    {
                        if( z == nodata_value && x > 0 )
                            gv_raster_get_sample(raster, x-1, y, &z,
                                                 &imaginary);

                        if( z == nodata_value && x < raster->width-1 )
                            gv_raster_get_sample(raster, x+1, y, &z,
                                                 &imaginary);

                        if( z == nodata_value && y > 0 )
                            gv_raster_get_sample(raster, x, y-1, &z,
                                                 &imaginary);

                        if( z == nodata_value && y < raster->height-1 )
                            gv_raster_get_sample(raster, x, y+1, &z,
                                                 &imaginary);

                        if( z == nodata_value && x > 1 )
                            gv_raster_get_sample(raster, x-2, y, &z,
                                                 &imaginary);

                        if( z == nodata_value && x < raster->width-2 )
                            gv_raster_get_sample(raster, x+2, y, &z,
                                                 &imaginary);

                        if( z == nodata_value && y > 1 )
                            gv_raster_get_sample(raster, x, y-2, &z,
                                                 &imaginary);

                        if( z == nodata_value && y < raster->height-2 )
                            gv_raster_get_sample(raster, x, y+2, &z,
                                                 &imaginary);

                        if( z == nodata_value )
                            z = last_z;
                        else
                            z += offset;

                        last_z = z;
                    }
                }

                gv_shape_set_xyz( shape, ring, node, x_orig, y_orig, z );
            }
        }
    }

    /* notify of completed change */
    gv_data_changed(GV_DATA(shapes), &change_info);

    g_free( id_list);
}