Select to view content in your preferred language

How get the data matrix in the order of "FID" from the fields of shpfile

3370
9
12-27-2012 06:11 AM
BinbinLu
New Contributor
I am scripting with python and ArcGIS 10.1. I want to get fied data from the shpfile, what I did are as follows:

ssdo = SSDO.SSDataObject(inputFC, templateFC=OutputFC)
masterField = UTILS.setUniqueIDField(ssdo, weightsFile=DistM)
self.allVars = [self.DeVar] + self.IndeVars
ssdo.obtainDataGA(masterField, self.allVars, minNumObs=5, warnNumObs=20)
self.y = ssdo.fields[self.DeVar].returnDouble()
self.x = NUM.ones((self.dp_n, self.var_n), dtype=float)
for i in range(1, self.var_n):
      self.x[:, i] = ssdo.fields[self.IndeVars[i - 1]].returnDouble()
....................

BUT I found the populated "y" and "x" data is not in the order of "FID",  for example:

In the original shpfile,
    (Intercept) FLOORSZ
0             1      54
1             1      82
2             1      65
3             1      90
4             1     132
5             1      76
6             1      56
7             1      76
8             1      48
9             1      45
10            1      87

BUT in the populated "x" data:
[   1.   80.]
[   1.   94.]
[   1.  150.]
[   1.   97.]
[   1.   83.]
[   1.   98.]
[   1.  254.]
[   1.  108.]
[   1.   80.]
[   1.  194.]


Anyone can tell me what happened here? And how can I make the populated data are in the order of FID?

Many many thanks!
Tags (2)
0 Kudos
9 Replies
markdenil
Frequent Contributor
try inserting the x and y values as a list into a dictionary keyed to the FID.
Then you can access them by key, and you can order the keys any way you want.

One can never tell what order the records in a database actually have;
any tool to look the contents of a database table actually shows you a view,
which is usually ordered on the index field.
The records themselves can be in any order, and they may not be in the same order at some other point in time.
0 Kudos
BinbinLu
New Contributor
Hi Mark, Many thanks for your reply.

I am begainer to use python, and Can you please give an example for this? Thanks again.


try inserting the x and y values as a list into a dictionary keyed to the FID.
Then you can access them by key, and you can order the keys any way you want.

One can never tell what order the records in a database actually have;
any tool to look the contents of a database table actually shows you a view,
which is usually ordered on the index field.
The records themselves can be in any order, and they may not be in the same order at some other point in time.
0 Kudos
markdenil
Frequent Contributor
a dictionary is intialized like this
adict = {}

then, once you extract the x, y, and fid from the record
you can add an entry keyed to the fid like this

adict[fid] = [x, y]

now your dictionary looks like this

{fid: [x, y]}  or, from your example,  {0: [1, 54]}

continue adding records, keyed to the respective fids
and you get a dictionary like this

{0: [1, 54], 1: [1, 82], 2: [1, 65], 3: [1, 90], 4: [1, 132], 5: [1, 76]}


reference the entries by the key  
adict[0] returns the list [1, 54],  so the x value for fid 0 is adict[0][0]

get a list of keys with adict.keys()

be aware that, just like the table, the dictionary keys can be in any order
so to order your output, you have to order your reference calls
(call the keys in the order you want: 0,1,2,3...)

hope that helps...
0 Kudos
by Anonymous User
Not applicable
Here is another way:

    srows = arcpy.SearchCursor(add)
    dictionary =dict([(r.OID,[r.POINT_X,r.POINT_Y]) for r in srows])
    for key,value in dictionary.iteritems():
        display = str(key) + " : " + str(value)
        print display


This returns:

0 : [2350777.4728, 594558.280203]
1 : [2253187.54954, 703592.805572]
2 : [2285922.63663, 652108.74942]
3 : [2287756.13231, 652063.65535]
4 : [2342506.34991, 687427.921891]
5 : [2253516.13747, 703548.009402]
6 : [2251173.05423, 702889.142281]
7 : [2252173.37801, 702899.971656]
8 : [2251146.67009, 702937.871514]
9 : [2251076.57509, 702964.549939]
10 : [2252051.53935, 702924.865307]
11 : [2280423.63778, 698390.86158]
12 : [2280502.55429, 698357.735005]
13 : [2228616.92381, 617827.380318]
0 Kudos
peterAnderson2
New Contributor
Can anyone tell me how to get Data Matrix in VB.NET? I want to create some Data Matrix barcodes in VB.NET. I googled and found tools like this. Must I use such a tool? And how can I choose a good one in the Internet? By this way, I read this guide of creating barcode in VB.NET and copied the sample code in my program. But it can not work. Why is this? Here is the sample code:
Imports OnBarcode.Barcode


Dim barcode As DataMatrix = New DataMatrix

' Data Matrix Barcode Basic Settings

barcode.Data = "112233445566"

barcode.DataMode = DataMatrixDataMode.ASCII

'if your selected format mode doesnot have enough space to encode your data,
'the library will choose the right format mode for you automatically.
barcode.FormatMode = DataMatrixFormatMode.Format_48X48

'Set the ProcessTilde property to true, if you want use the tilde character "~"
'to specify special characters in the input data. Default is false.

'1) 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255);
'   ASCII character '~' is presented by ~126;
'   Strings from "~256" to "~299" are unused
'   modified to FS, GS, RS and US respectively.
'2) 2-byte character (Unicode): ~6ddddd (character value from 00000 ~ 65535)
'   Strings from "~665536" to "~699999" are unused
'3) for GS1 AI Code:
'   ~ai2: AI with 2 digits
'   ~ai3: AI with 3 digits
'   ~ai4: AI with 4 digits
'   ~ai5: AI with 5 digits
'   ~ai6: AI with 6 digits
'   ~ai7: AI with 7 digits
'4) ECI: ~7dddddd (valid value of dddddd from 000000 to 999999)
'5) ~rp: Reader Programming (for ASCII mode and Auto mode only)
'6) ~m5: 05 Macro (for ASCII mode and Auto mode only)
'7) ~m6: 06 Macro (for ASCII mode and Auto mode only)
barcode.ProcessTilde = True

' Barcode Size Related Settings
barcode.UOM = UnitOfMeasure.PIXEL
   barcode.X = 3
barcode.LeftMargin = 0
   barcode.RightMargin = 0
barcode.TopMargin = 0
   barcode.BottomMargin = 0
barcode.Resolution = 96
   barcode.Rotate = Rotate.Rotate0

' Image format setting
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif()

barcode.drawBarcode("c://data-matrix.gif")
0 Kudos
dannyrough
Emerging Contributor
Can anyone tell me how to get Data Matrix in VB.NET? I want to create some Data Matrix barcodes in VB.NET. I googled and found tools like this. Must I use such a tool? And how can I choose a good one in the Internet? By this way, I read this guide of creating barcode in VB.NET and copied the sample code in my program. But it can not work. Why is this? Here is the sample code:
Imports OnBarcode.Barcode


Dim barcode As DataMatrix = New DataMatrix

' Data Matrix Barcode Basic Settings

barcode.Data = "112233445566"

barcode.DataMode = DataMatrixDataMode.ASCII

'if your selected format mode doesnot have enough space to encode your data,
'the library will choose the right format mode for you automatically.
barcode.FormatMode = DataMatrixFormatMode.Format_48X48

'Set the ProcessTilde property to true, if you want use the tilde character "~"
'to specify special characters in the input data. Default is false.

'1) 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255);
'   ASCII character '~' is presented by ~126;
'   Strings from "~256" to "~299" are unused
'   modified to FS, GS, RS and US respectively.
'2) 2-byte character (Unicode): ~6ddddd (character value from 00000 ~ 65535)
'   Strings from "~665536" to "~699999" are unused
'3) for GS1 AI Code:
'   ~ai2: AI with 2 digits
'   ~ai3: AI with 3 digits
'   ~ai4: AI with 4 digits
'   ~ai5: AI with 5 digits
'   ~ai6: AI with 6 digits
'   ~ai7: AI with 7 digits
'4) ECI: ~7dddddd (valid value of dddddd from 000000 to 999999)
'5) ~rp: Reader Programming (for ASCII mode and Auto mode only)
'6) ~m5: 05 Macro (for ASCII mode and Auto mode only)
'7) ~m6: 06 Macro (for ASCII mode and Auto mode only)
barcode.ProcessTilde = True

' Barcode Size Related Settings
barcode.UOM = UnitOfMeasure.PIXEL
   barcode.X = 3
barcode.LeftMargin = 0
   barcode.RightMargin = 0
barcode.TopMargin = 0
   barcode.BottomMargin = 0
barcode.Resolution = 96
   barcode.Rotate = Rotate.Rotate0

' Image format setting
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif()

barcode.drawBarcode("c://data-matrix.gif")


thanks for sharing! the toolkits you shared are really useful!
0 Kudos
makaveiljojo
Emerging Contributor
Hi petersea,
To get Data Matrix barcode images, a Data Matrix font is required. But there are also a couple of other ways of generating Data Matrix, like getting a Data Matrix ASP.NET control or a professional generator.
I'm not so sure I read and understand the code you posted well. But my suggestion is to get open sources and try. If you have to use a commercial product, at least try a few trial versions before you get licensed.
0 Kudos
mariahlewis
Emerging Contributor
as for data matrix i just generated it using .net program ,not knowing whether helps?
0 Kudos
fdsffdsf
Emerging Contributor
as for   data matrix i just generated it using .net program ,not knowing whether helps?


hello, cindy. how do you do it. i need more detailed information.
0 Kudos