2

I have two almost identical shapefiles (polylines) representing a road network. The only difference is that the original shapefile has lines that have different lengths, while the other shapefile has a set length of 1000 meter.

While creating the equal sections of 1000 meters, the attribute table of the original shapefile with different lengths was lost. This also means that the new shapefile contains more Objects than the original shapefile.

Is there a way to copy the attributes from the original shapefile to the new shapefile? The attributes from the original need to be copied to all the objects that are at the same location in the new shapefile.

The first picture contains the original layer with classification as Major Road (please note, between two intersections there is only 1 object, unlike in the new layer). The second picture contains the new layer without classification and the third one contains the picture when using spatial join in ArcGis. Original New Spatial Join

3
  • 1
    You have tags for QGIS and ArcGIS for Desktop but to prevent this being effectively two questions, and thus too broad, which will you actually be more likely to use?
    – PolyGeo
    Aug 4, 2016 at 11:03
  • QGIS has the Join attributes by location tool; ArcGIS has the Spatial Join tool.
    – Joseph
    Aug 4, 2016 at 11:04
  • Excuse the use of both tags. This was the only operation I need to do in GIS so I figured I would just use the easiest one.
    – Martin
    Aug 4, 2016 at 11:34

1 Answer 1

0

The workflow suggested will work as long as the relationship between the two later is 1:n (or 1:1), namely that each line in the original shape corresponds to 1 or more lines in the 1000 meters layer, but not vice versa (i.e. not n:n).

I demonstrate the workflow on arcgis, but it will work for qgis as well.

Prior to this answer, I've suggested a spatial join, that didn't work for the OP. In addition it didn't work well for QGIS. Thus, here is a work around this problem using a mediating layer of line centroids (midpoints)

  • Create a point layer in which each point is a centorid / midpoint of one line from your 1000 meters layer. I've used Feature vertices to points, with MID as the vertex I want.
  • Than I've performed a spatial join; joining attributes from the original lines layer to the points. The definitions used in the join menu are shown below.

Spatial Join

  • Finally I've used join by attributes on the 1000 meter lines with the points, matching FID (1000 meter line) to ORIG_FID (Midpoint layer).

Join by Attributes

That should solve the problem.

For Qgis you can use geomToWKT( centroid( $geometry ) ) in field calculator the get a WKT string of the centroid, taken from here, and work from there to create your mid point layer.

3
  • I have tried using spatial join and it seems that it has a similar problem as the one you described in QGIS. When the new shapefile contains multiple lines on the same location as the original shapefile, it does not copy the attributes correctly, in fact, it does not copy them to any of the new lines. It only joins the attributes corectly if the original line was already under 1000 meters (and therefore the relationship is 1:1 between the original and the new shapefile).
    – Martin
    Aug 4, 2016 at 11:41
  • In my example I've created a 1:n relationship and it seems to be working well. Yet it is a very simple dataset. Can you edit your question with an image illustrating the problem?
    – dof1985
    Aug 4, 2016 at 11:45
  • @Martin, see edits with a proposed work -around...
    – dof1985
    Aug 4, 2016 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.