enter image description hereenter image description here

How can i use the value in column 'lon' and 'lat' as the position of my uv_sphere? For example,read the values from line 4, (116.4559081, 39.9139083), and make these 2 numbers as my uv_sphere x and y position in blender? and gives different colors for different mode, for example i have 4 modes in the csv , i want to make the uv sphere that represents the bus mode to be red, and subway to be green , rail to be blue and tram to be yellow., and use the row ['from'] and ['to'] to connect the nodes with a cylinder with x scale 0.5 , y scale 0.5 and the z scale with the value in ['length'] value.

  • 1
    $\begingroup$ Are the x and y positions going to be vertices or objects? $\endgroup$ – Ray Mairlot Jan 16 '17 at 12:08
  • $\begingroup$ @RayMairlot, hi...thank you for responding , i want to make a uv sphere at with those numbers . $\endgroup$ – JeffFederick Jan 16 '17 at 12:34
  • 1
    $\begingroup$ Also look into: github.com/domlysz/BlenderGIS and github.com/vvoovv/blender-osm You may find way to do a correct mapping of lat long to x y, otherwise it may appear stretched vertically or horizontally... and one or both of those links may let you link concordances to an actual map. Also you might find QGIS to be a better tool for what you're trying to do. $\endgroup$ – James Thomas Jan 16 '17 at 14:19
  • $\begingroup$ I have just seen that this is the second time you have asked this question (blender.stackexchange.com/questions/71458/…). You shouldn't have asked the same question again. If you needed to update the original question then you should have 'edited' it. $\endgroup$ – Ray Mairlot Jan 16 '17 at 14:45
  • $\begingroup$ @RayMairlot hi sir, can you help? $\endgroup$ – JeffFederick Feb 22 '17 at 12:20

enter image description here

You can use the csv library to read and parse CSVs. If you have a basic bus object on a different layer (or a sphere called bus), this script will duplicate it and then assign the longitude and latitude values from your CSV as the new object's x and y values, for each row in your CSV.

import bpy, csv

fp = "C:/csvs/buses.csv"

with open( fp ) as csvfile:
    rdr = csv.reader( csvfile )
    for i, row in enumerate( rdr ):
        if i == 0: continue # Skip column titles
        lon, lat = row[3:5]

        # Generate UV sphere at x = lon and y = lat (and z = 0 )
        bpy.ops.mesh.primitive_uv_sphere_add( location = ( float(lon), float(lat), 0 ) )

I used this CSV to test this code:

  • $\begingroup$ hey thank you for responding :D, that looks awesome, but somehow when i try to copy your code, i have an error on line 7. the one that " for i, row in enumerate( rdr ): ", how should i change it to make it work? please help. and i want to make a uv_sphere with it $\endgroup$ – JeffFederick Jan 16 '17 at 12:36
  • $\begingroup$ Can you specify the error you're getting from the console? $\endgroup$ – TLousky Jan 16 '17 at 12:38
  • $\begingroup$ it just says " Python script fail, look in the console now . . . " import bpy, csv with open('C:\\Users\\Jeff\\Desktop\\Thesis\\nodes.csv') as csvfile: rdr = csv.reader( csvfile ) for i, row in enumerate( rdr ): if i == 0: continue # Skip column titles mode, ctry, id, lon, lat = row[:] # Duplicate basic bus object o = bpy.data.objects["uv_sphere"].copy() o.layers = [ i == 0 for i in range(20) ] bpy.context.scene.objects.link( o ) o.location.x = float( lon ) o.location.y = float( lat ) $\endgroup$ – JeffFederick Jan 16 '17 at 12:40
  • $\begingroup$ You can open a console window through the Window menu --> Toggle System Console. The console output should be more explicit. $\endgroup$ – TLousky Jan 16 '17 at 12:41
  • 1
    $\begingroup$ @JeffFederick Is there a column "F" in your data. The code is only trying to unpack 5 vars, if there are more or less you need to adjust accordingly. $\endgroup$ – batFINGER Jan 16 '17 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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